/*****************************************************************************
 * DESC       ：组合险标的批单编辑脚本页面
 * AUTHOR     ：安盟项目组
 * CREATEDATE ：2013-11-18
 * MODIFYLIST ：  Name      Date      Reason/Contents
 *          --------------------------------------------------
 ****************************************************************************/

//主险
function insertItemKindMain()
{ 
  var intRowsCount = getRowsCount("ItemKindMain");

  insertRowForPG('ItemKindMain','ItemKindMain_Data');
  
  setcloneNodeEventOfTablePG("ItemKindMain");
  
  fm.StartDateMain[intRowsCount+1].value = fm.ValidDate.value;
  fm.EndDateMain[intRowsCount+1].value = fm.EndDate.value;
  resetItemKindNo(); //该函数在框架的js中
  setItemKindAddressNo();// 若被保险财产座落地址不为空将在主险中自动带出序号
  calculatePremiumMain(fm.ShortRateFlagMain[intRowsCount + 1],1);//计算短期费率
}
function insertItemKindLossMainSub()
{ 
  var intRowsCount = getRowsCount("ItemKindLossMainSub");

  insertRowForPG('ItemKindMain','ItemKindLossMainSub_Data');
  
  setcloneNodeEventOfTablePG("ItemKindLossMainSub");
  
  fm.StartDateMain[intRowsCount+1].value = fm.ValidDate.value;
  fm.EndDateMain[intRowsCount+1].value = fm.EndDate.value;
  resetItemKindNo(); //该函数在框架的js中
  setItemKindAddressNo();// 若被保险财产座落地址不为空将在主险中自动带出序号
  calculatePremiumMain(fm.ShortRateFlagMain[intRowsCount + 1],1);//计算短期费率
}

function deleteItemKindMain(field,intPageDataKeyCount,intRowsCount)
{
  var index = getElementOrder(field)-1;
  var strFlag = fm.ItemKindMain_Flag[index].value;
 
  deleteRowForPG('ItemKindMain','ItemKindMain_Data',field,intPageDataKeyCount,intRowsCount);
  mainChangePerumSubdelete(field);
  resetItemKindNo();
  if(strFlag!="I"&&strFlag!="D")
  {
    fm.AmountMain[index].value = "0.00";
    mainChangePerumSubdelete(field);
    calculatePremiumMain(fm.AmountMain[index],1); //删除时需要重新计算短期系数
    //setRefreshFlagFeeZero();
  }
}

 function jsSelectIsExitItem(objSelect, objItemValue) {        
    var isExit = false;        
    for (var i = 0; i < objSelect.options.length; i++) {        
        if (objSelect.options[i].value == objItemValue) {        
            isExit = true;        
            break;        
        }        
    }        
    return isExit;        
}  

function getItemKindMain()
{  
  var arrayItemKindMainRow = new Array();
  var arrayItemKindMain = new Array();
  var strRiskCode = fm.RiskCode.value;
  var i = 0;
  var j = 0;

  for(i=1;i<=getRowsCount("ItemKindMain");i++)
  {
    arrayItemKindMainRow = new Array();

    arrayItemKindMainRow.KindCode = fm.KindCodeMain[i].value;
    arrayItemKindMainRow.KindName = fm.KindNameMain[i].value;
    //xiaojian_leave：在页面上增加是否算入总保额的隐藏字段，在初始化文件中赋值：PrpDkind.CalculateFlag[1]
    //if(strRiskCode=="6603" || strRiskCode=="6602" || strRiskCode=="6606"){
    	arrayItemKindMainRow.CalculateFlag = fm.CalculateFlagMain[i].value;
    //}else{
    //	arrayItemKindMainRow.CalculateFlag = "Y";
    //}
    arrayItemKindMainRow.ItemCode = fm.ItemCodeMain[i].value;
    arrayItemKindMainRow.ItemName = fm.ItemNameMain[i].value;
    arrayItemKindMainRow.ItemDetailName = fm.ItemDetailNameMain[i].value;
    arrayItemKindMainRow.ModeCode = fm.ModeCodeMain[i].value;
    arrayItemKindMainRow.ModeName = fm.ModeNameMain[i].value;
    arrayItemKindMainRow.Currency = fm.CurrencyMain[i].value;
    arrayItemKindMainRow.CurrencyName = fm.CurrencyNameMain[i].value;
    arrayItemKindMainRow.ExchangeRate = fm.ExchangeRateMain[i].value;
    arrayItemKindMainRow.Amount = parseFloat(fm.AmountMain[i].value);
    //modify by tonyJ
    if(fm.RateMain!=undefined){
    	arrayItemKindMainRow.Rate = parseFloat(fm.RateMain[i].value);
    }
    if(fm.DiscountMain!=undefined){
    	arrayItemKindMainRow.Discount = parseFloat(fm.DiscountMain[i].value);
    }
    arrayItemKindMainRow.Premium = parseFloat(fm.PremiumMain[i].value);

    if(isNaN(arrayItemKindMainRow.ExchangeRate))
      arrayItemKindMainRow.ExchangeRate = 0;
    if(isNaN(arrayItemKindMainRow.Amount))
      arrayItemKindMainRow.Amount = 0;
    if(isNaN(arrayItemKindMainRow.Rate))
      arrayItemKindMainRow.Rate = 0;
    if(isNaN(arrayItemKindMainRow.Discount))
      arrayItemKindMainRow.Discount = 0;
    if(isNaN(arrayItemKindMainRow.Premium))
      arrayItemKindMainRow.Premium = 0;

    arrayItemKindMain[arrayItemKindMain.length] = arrayItemKindMainRow; //一个标的信息
  }

  return arrayItemKindMain;
}
function getItemKindMain6603() {
	var arrayItemKindMainRow = new Array();
	var arrayItemKindMain = new Array();
	var strRiskCode = fm.RiskCode.value;
	var i = 0;
	var j = 0;
	for (i = 1; i <= getRowsCount("ItemKindMain"); i++) {
		arrayItemKindMainRow = new Array();

		arrayItemKindMainRow.KindCode = fm.KindCodeMain[i].value;
		arrayItemKindMainRow.KindName = fm.KindNameMain[i].value;
		// xiaojian_leave：在页面上增加是否算入总保额的隐藏字段，在初始化文件中赋值：PrpDkind.CalculateFlag[1]
		arrayItemKindMainRow.CalculateFlag = fm.CalculateFlagMain[i].value;
		//arrayItemKindMainRow.CalculateFlag = "Y";
		if(fm.ItemCodeMain!=null && fm.ItemCodeMain[i]!=null){
		  arrayItemKindMainRow.ItemCode = fm.ItemCodeMain[i].value;
		}
		if(fm.ItemNameMain!=null && fm.ItemNameMain[i]!=null){
		  arrayItemKindMainRow.ItemName = fm.ItemNameMain[i].value;
		}
		if(fm.ItemDetailNameMain!=null && fm.ItemDetailNameMain[i]!=null){
		  arrayItemKindMainRow.ItemDetailName = fm.ItemDetailNameMain[i].value;
		}
		if(fm.ModeCodeMain!=null && fm.ModeCodeMain[i]!=null){
		  arrayItemKindMainRow.ModeCode = fm.ModeCodeMain[i].value;
		}
		if(fm.ModeNameMain!=null && fm.ModeNameMain[i]!=null){
		  arrayItemKindMainRow.ModeName = fm.ModeNameMain[i].value;
		}
		
		arrayItemKindMainRow.Currency = fm.CurrencyMain[i].value;
		arrayItemKindMainRow.CurrencyName = fm.CurrencyNameMain[i].value;
		arrayItemKindMainRow.ExchangeRate = fm.ExchangeRateMain[i].value;
		arrayItemKindMainRow.Amount = parseFloat(fm.AmountMain[i].value);
		arrayItemKindMainRow.Rate = parseFloat(fm.RateMain[i].value);
		arrayItemKindMainRow.Discount = parseFloat(fm.DiscountMain[i].value);
		arrayItemKindMainRow.Premium = parseFloat(fm.PremiumMain[i].value);

		if (isNaN(arrayItemKindMainRow.ExchangeRate))
			arrayItemKindMainRow.ExchangeRate = 0;
		if (isNaN(arrayItemKindMainRow.Amount))
			arrayItemKindMainRow.Amount = 0;
		if (isNaN(arrayItemKindMainRow.Rate))
			arrayItemKindMainRow.Rate = 0;
		if (isNaN(arrayItemKindMainRow.Discount))
			arrayItemKindMainRow.Discount = 0;
		if (isNaN(arrayItemKindMainRow.Premium))
			arrayItemKindMainRow.Premium = 0;
        
		arrayItemKindMain[arrayItemKindMain.length] = arrayItemKindMainRow; // 一个标的信息
	}
	
	
	return arrayItemKindMain;
}
function getOldItemKindMain()
{
  var arrayItemKindMainRow = new Array();
  var arrayItemKindMain = new Array();
  var i = 0;
  var j = 0;

  for(i=1;i<=getRowsCount("ItemKindMain");i++)
  {
    arrayItemKindMainRow = new Array();

    arrayItemKindMainRow.KindCode = fm.KindCodeMain[i].title;
    arrayItemKindMainRow.KindName = fm.KindNameMain[i].title;
    arrayItemKindMainRow.CalculateFlag = fm.CalculateFlagMain[i].title;
    arrayItemKindMainRow.ItemCode = fm.ItemCodeMain[i].title;
    arrayItemKindMainRow.ItemName = fm.ItemNameMain[i].title;
    arrayItemKindMainRow.ItemDetailName = fm.ItemDetailNameMain[i].title;
    arrayItemKindMainRow.ModeCode = fm.ModeCodeMain[i].title;
    arrayItemKindMainRow.ModeName = fm.ModeNameMain[i].title;
  
    arrayItemKindMainRow.Currency = fm.CurrencyMain[i].title;
    arrayItemKindMainRow.CurrencyName = fm.CurrencyNameMain[i].title;
    arrayItemKindMainRow.ExchangeRate = fm.ExchangeRateMain[i].title;
    arrayItemKindMainRow.Amount = parseFloat(fm.AmountMain[i].title);
    if(fm.RateMain!=undefined){
    	arrayItemKindMainRow.Rate = parseFloat(fm.RateMain[i].title);
    }
    arrayItemKindMainRow.Discount = parseFloat(fm.DiscountMain[i].title);
    arrayItemKindMainRow.Premium = parseFloat(fm.PremiumMain[i].title);

    if(isNaN(arrayItemKindMainRow.ExchangeRate))
      arrayItemKindMainRow.ExchangeRate = 0;
    if(isNaN(arrayItemKindMainRow.Amount))
      arrayItemKindMainRow.Amount = 0;
    if(isNaN(arrayItemKindMainRow.Rate))
      arrayItemKindMainRow.Rate = 0;
    if(isNaN(arrayItemKindMainRow.Discount))
      arrayItemKindMainRow.Discount = 0;
    if(isNaN(arrayItemKindMainRow.Premium))
      arrayItemKindMainRow.Premium = 0;

    arrayItemKindMain[arrayItemKindMain.length] = arrayItemKindMainRow; //一个标的信息
  }

  return arrayItemKindMain;
}

function getCollectItemKindMain()
{
  var arrayItemKindMain = new Array();
  return arrayItemKindMain;
}

function calculatePremiumMain(field,strCalculateShortRateFlag)
{
  var index = getElementOrder(field)-1;
  //if(parseInt(strCalculateShortRateFlag,10)==1)
	if(fm.all("UnitAmountMain")[index].style.display != "none") {
	fm.all("AmountMain")[index].value = calculateAmountMain(index);
	}else{
	fm.all("UnitAmountMain")[index].value = fm.all("AmountMain")[index].value;
	fm.all("QuantityMain")[index].value = 1;
	}
    fm.all("ShortRateMain")[index].value = pointFour(round(calShortRate(index,"Main"),4));
  fm.all("PremiumMain")[index].value = pointTwo(round(formulizePremium(index,"Main"),2));
  setRefreshFlagFeeZero();
}
function calculatePremiumMain6603(field,strCalculateShortRateFlag)
{
  var index = getElementOrder(field)-1;
  //if(parseInt(strCalculateShortRateFlag,10)==1)
    fm.all("ShortRateMain")[index].value = pointFour(round(calShortRate(index,"Main"),4));
  fm.all("PremiumMain")[index].value = pointTwo(round(formulizePremium6603(index,"Main"),2));
  setRefreshFlagFeeZero();
}
/**changuish  6603保费计算，因为保费因子中多了个加费比例**/
function calculatePremiumMainAddFeeRate(field) {
	var strRiskCode = fm.RiskCode.value;
	var index = getElementOrder(field) - 1;
	var value1 = parseFloat(fm.all("AmountMain")[index].value);//保额
	var value2 = parseFloat(fm.all("RateMain")[index].value);//年费率
	var value3 = parseFloat(fm.all("AjustRateMain")[index].value);//加费比例
	var value;
	fm.all("PremiumMain")[index].value = pointTwo(round(value,2));
}

function calculatePremiumMainOnlyZero(field,strCalculateShortRateFlag)
{ 
  if(field.value==""&&parseFloat(field.value)!=0)
    return;
  calculatePremiumMain(field,strCalculateShortRateFlag);
}

function setSumAmountPremiumToItemKindMain(dbSumAmountMain,dbSumPremiumMain)
{
  fm.SumAmountMain.value = pointTwo(round(dbSumAmountMain,2));
  fm.CurrencySumAmountMain.value = fm.Currency2Fee.value
  fm.CurrencyNameSumAmountMain.value = fm.CurrencyName2Fee.value;
  fm.SumPremiumMain.value = pointTwo(round(dbSumPremiumMain,2));
  fm.CurrencySumPremiumMain.value = fm.Currency2Fee.value
  fm.CurrencyNameSumPremiumMain.value = fm.CurrencyName2Fee.value;
}

function checkItemKindMain()
{
  var intRowsCount = getRowsCount("ItemKindMain");
  var i = 0;
  //校验之前如果没展开的话先打开，校验没有问题后关闭掉
  elements =document.getElementsByName( "ItemKindMainImg");
  openPage(elements[0],ItemKindMain);
  var result =true;
  var resulttemp =true;
  var AllMessage="主险信息模块校验不通过，请关注红色录入域,重新填写正确的保单信息\n";
  var arryList=['KindCodeMain','KindNameMain','ItemNameMain','ItemDetailNameMain','AddressNoMain','CurrencyMain','UnitAmountMain','QuantityMain','AmountMain','ModeCodeMain','FamilyNameMain','RateMain','AjustRateMain','PremiumMain'];
  if(intRowsCount==0)
  {
    errorMessage("请输入主险信息！");
    showPageOnly(document.ItemKindMainImg,ItemKindMain); //在UICommon.js中，只是显示并没有隐藏作用的函数
    insertItemKindMain();
    return false;
  }
  for(i=1;i<=intRowsCount;i++)
  {
	    resulttemp = saveMessageValid(i,arryList,"");
		 if(resulttemp==false){
			 result =false;
			 }	
	  
  }
  if(result==false){
      setcrollTo(elements[0]);
      ErrAllMessage(AllMessage);
  return  false;
  }
  
  for(i=1;i<=intRowsCount;i++)
  {

    if(!checkAddressNo(fm.AddressNoMain[i])){
    	return false;
    }
    if(!isInteger(fm.AddressNoMain[i].value))
    {
      errorMessage(fm.AddressNoMain[i].description+"序号不能为空且为数字!");
      showPageOnly(document.ItemKindMainImg,ItemKindMain);
      fm.AddressNoMain[i].focus();
      return false;
    }
    //给保险金额，年费率，保费等添加验证，为零则不通过

    if(fm.ItemKindMain_Flag[i].value!='D'){
	    if(isEmpty(fm.AmountMain[i])||parseFloat(fm.AmountMain[i].value)<=0)
	    {
	      errorMessage("主险保额录入错误!");
	      showPageOnly(document.ItemKindMainImg,ItemKindMain);
	      fm.AmountMain[i].focus();
	      return false;
	    }
	    if(fm.RateMain!=undefined){
	    	if(isEmpty(fm.RateMain[i])||parseFloat(fm.RateMain[i].value)<=0)
		    {
		      errorMessage("主险年费率录入错误!");
		      showPageOnly(document.ItemKindMainImg,ItemKindMain);
		      fm.RateMain[i].focus();
		      return false;
		    }
	    }
	    if(isEmpty(fm.PremiumMain[i])||parseFloat(fm.PremiumMain[i].value)<=0)
	    {
	      errorMessage("主险保费录入错误!");
	      showPageOnly(document.ItemKindMainImg,ItemKindMain);
	      fm.PremiumMain[i].focus();
	      return false;
	    }
    }

  }
  setFlagPG('ItemKindMain',2);
  closePage(elements[0],ItemKindMain);
  return true;
}

//附加险/附加条款
function insertItemKindSub()
{
  var intRowsCount = getRowsCount("ItemKindSub");
  insertRowForPG('ItemKindSub','ItemKindSub_Data');
  
  setcloneNodeEventOfTablePG("ItemKindSub");
  
  fm.StartDateSub[intRowsCount+1].value = fm.ValidDate.value;
  fm.EndDateSub[intRowsCount+1].value = fm.EndDate.value;
  resetItemKindNo(); //该函数在框架的js中
  calculatePremiumSub(fm.ShortRateSub[intRowsCount+1], 1);
}

function deleteItemKindSub(field,intPageDataKeyCount,intRowsCount)
{
  var index = getElementOrder(field)-1;
  var strFlag = fm.ItemKindSub_Flag[index].value;
  deleteRowForPG('ItemKindSub','ItemKindSub_Data',field,intPageDataKeyCount,intRowsCount);
  resetItemKindNo();
  if(strFlag!="I"&&strFlag!="D")
  {
    fm.AmountSub[index].value = "0.00";
    calculatePremiumSub(fm.AmountSub[index],1);
    //setRefreshFlagFeeZero();
  }
}

function getItemKindSub()
{
  var arrayItemKindSubRow = new Array();
  var arrayItemKindSub = new Array();
  var i = 0;
  var j = 0;
  
  for(i=1;i<=getRowsCount("ItemKindSub");i++)
  {
    arrayItemKindSubRow = new Array();
   
    arrayItemKindSubRow.KindCode = fm.KindCodeSub[i].value;
    arrayItemKindSubRow.KindName = fm.KindNameSub[i].value;
    //xiaojian_leave：在页面上增加是否算入总保额的隐藏字段，在初始化文件中赋值：PrpDkind.CalculateFlag[1]
    arrayItemKindSubRow.CalculateFlag = fm.CalculateFlagSub[i].value;
    arrayItemKindSubRow.ItemCode = fm.ItemCodeSub[i].value;
    arrayItemKindSubRow.Currency = fm.CurrencySub[i].value;
    arrayItemKindSubRow.CurrencyName = fm.CurrencyNameSub[i].value;
    arrayItemKindSubRow.ExchangeRate = fm.ExchangeRateSub[i].value;
    arrayItemKindSubRow.Amount = parseFloat(fm.AmountSub[i].value);
    arrayItemKindSubRow.Rate = parseFloat(fm.RateSub[i].value);
    arrayItemKindSubRow.Discount = parseFloat(fm.DiscountSub[i].value);
    arrayItemKindSubRow.Premium = parseFloat(fm.PremiumSub[i].value);

    if(isNaN(arrayItemKindSubRow.ExchangeRate))
      arrayItemKindSubRow.ExchangeRate = 0;
    if(isNaN(arrayItemKindSubRow.Amount))
      arrayItemKindSubRow.Amount = 0;
    if(isNaN(arrayItemKindSubRow.Rate))
      arrayItemKindSubRow.Rate = 0;
    if(isNaN(arrayItemKindSubRow.Discount))
      arrayItemKindSubRow.Discount = 0;
    if(isNaN(arrayItemKindSubRow.Premium))
      arrayItemKindSubRow.Premium = 0;

    arrayItemKindSub[arrayItemKindSub.length] = arrayItemKindSubRow; //一个标的信息
  }

  return arrayItemKindSub;
}

function getOldItemKindSub()
{
  var arrayItemKindSubRow = new Array();
  var arrayItemKindSub = new Array();
  var i = 0;
  var j = 0;

  for(i=1;i<=getRowsCount("ItemKindSub");i++)
  {
    arrayItemKindSubRow = new Array();

    arrayItemKindSubRow.KindCode = fm.KindCodeSub[i].title;
    arrayItemKindSubRow.KindName = fm.KindNameSub[i].title;
    //xiaojian_leave：在页面上增加是否算入总保额的隐藏字段，在初始化文件中赋值：PrpDkind.CalculateFlag[1]
    arrayItemKindSubRow.CalculateFlag = fm.CalculateFlagSub[i].title;
    arrayItemKindSubRow.ItemCode = fm.ItemCodeSub[i].title;
    arrayItemKindSubRow.Currency = fm.CurrencySub[i].title;
    arrayItemKindSubRow.CurrencyName = fm.CurrencyNameSub[i].title;
    arrayItemKindSubRow.ExchangeRate = fm.ExchangeRateSub[i].title;
    arrayItemKindSubRow.Amount = parseFloat(fm.AmountSub[i].title);
    arrayItemKindSubRow.Rate = parseFloat(fm.RateSub[i].title);
    arrayItemKindSubRow.Discount = parseFloat(fm.DiscountSub[i].title);
    arrayItemKindSubRow.Premium = parseFloat(fm.PremiumSub[i].title);

    if(isNaN(arrayItemKindSubRow.ExchangeRate))
      arrayItemKindSubRow.ExchangeRate = 0;
    if(isNaN(arrayItemKindSubRow.Amount))
      arrayItemKindSubRow.Amount = 0;
    if(isNaN(arrayItemKindSubRow.Rate))
      arrayItemKindSubRow.Rate = 0;
    if(isNaN(arrayItemKindSubRow.Discount))
      arrayItemKindSubRow.Discount = 0;
    if(isNaN(arrayItemKindSubRow.Premium))
      arrayItemKindSubRow.Premium = 0;

    arrayItemKindSub[arrayItemKindSub.length] = arrayItemKindSubRow; //一个标的信息
  }

  return arrayItemKindSub;
}

function getCollectItemKindSub()
{
  var arrayItemKindSub = new Array();
  return arrayItemKindSub;
}

function calculatePremiumSub(field,strCalculateShortRateFlag)
{
  var index = getElementOrder(field)-1;
  //if(parseInt(strCalculateShortRateFlag,10)==1)
   fm.all("ShortRateSub")[index].value = pointFour(round(calShortRate(index,"Sub"),4));
  fm.all("PremiumSub")[index].value = pointTwo(round(formulizePremium(index,"Sub"),2));
  setRefreshFlagFeeZero();
}

function calculatePremiumSubOnlyZero(field,strCalculateShortRateFlag)
{
  if(field.value==""&&parseFloat(field.value)!=0)
    return;
  calculatePremiumSub(field,strCalculateShortRateFlag);
}

function setSumAmountPremiumToItemKindSub(dbSumAmountSub,dbSumPremiumSub)
{
  fm.SumAmountSub.value = pointTwo(round(dbSumAmountSub,2));
  fm.CurrencySumAmountSub.value = fm.Currency2Fee.value
  fm.CurrencyNameSumAmountSub.value = fm.CurrencyName2Fee.value;
  fm.SumPremiumSub.value = pointTwo(round(dbSumPremiumSub,2));
  fm.CurrencySumPremiumSub.value = fm.Currency2Fee.value
  fm.CurrencyNameSumPremiumSub.value = fm.CurrencyName2Fee.value;
}

function checkItemKindSub()
{
  var intRowsCount = getRowsCount("ItemKindSub");
  var i = 0;
  var result =true;
  var resulttemp =true;
  var AllMessage="附加险信息模块校验不通过，请关注红色录入域,重新填写正确的保单信息\n";
  //校验之前如果没展开的话先打开，校验没有问题后关闭掉
  elements =document.getElementsByName( "ItemKindSubImg");
  openPage(elements[0],ItemKindSub);
 var arryList= ['KindCodeSub','KindNameSub','CurrencySub','UnitAmountSub','QuantitySub','ValueSub','AmountSub','FamilyNameSub','RateSub','PremiumSub','ItemKindSub_Context'];
 for(i=1;i<=intRowsCount;i++)
 { 
	 resulttemp = saveMessageValid(i,arryList,"");
	 if(resulttemp==false){
		 result =false;
		 }
 }
 if(result==false){
     
     setcrollTo(elements[0]);
     ErrAllMessage(AllMessage);
     
 return  false;
 }
  for(i=1;i<=intRowsCount;i++)
  {  
    for(j=i+1;j<=intRowsCount;j++){
      if(fm.KindCodeSub[i].value==fm.KindCodeSub[j].value){
        errorMessage(fm.KindCodeSub[i].description+"不能重复录入！");
        showPageOnly(document.ItemKindSubImg,ItemKindSub);
        fm.KindCodeSub[j].focus();
        return false;
      }
    }
    if(isEmpty(fm.CurrencySub[i]||isEmpty(fm.CurrencyNameSub[i])))
    {
      errorMessage(fm.CurrencyNameSub[i].description+"不能为空！");
      showPageOnly(document.ItemKindSubImg,ItemKindSub);
      fm.CurrencyNameSub[i].focus();
      return false;
    }
  }
  if(CheckThisSubRiskAmount() == false){
		return false;
  }
  setFlagPG('ItemKindSub',2);
  setItemKindSubEngageFlagPG();
  setItemKindSubDetailEngageFlagPG();
  closePage(elements[0],ItemKindSub);
  return true;
}

function setItemKindSubEngageFlagPG()
{
  var index = 0;
  for(index=1;index<=getRowsCount("ItemKindSub");index++)
  {
	fm.ItemKindSubEngage_Flag[index].value = "";
	
    if(fm.ItemKindSub_Flag[index].value!="U")
    {
      fm.ItemKindSubEngage_Flag[index].value = fm.ItemKindSub_Flag[index].value;
    }
    else
    {
     
	      if(fm.ItemKindSub_Context[index].value!=fm.ItemKindSub_Context[index].title)
	      {
	        fm.ItemKindSubEngage_Flag[index].value = "U";
	      }
	      if(fm.DeductibleRateSub[index].value!=fm.DeductibleRateSub[index].title||
	         fm.ShortRateFlagSub[index].value!=fm.ShortRateFlagSub[index].title||
	         fm.ShortRateSub[index].value!=fm.ShortRateSub[index].title||
	         fm.KindCodeSub[index].value!=fm.KindCodeSub[index].title||
	         fm.KindNameSub[index].value!=fm.KindNameSub[index].title||
	         //fm.ItemNameSub[index].value!=fm.ItemNameSub[index].title||
	         //fm.ItemDetailNameSub[index].value!=fm.ItemDetailNameSub[index].title||
	         fm.CurrencySub[index].value!=fm.CurrencySub[index].title||
	         fm.AmountSub[index].value!=fm.AmountSub[index].title||
	         fm.RateSub[index].value!=fm.RateSub[index].title||
	         fm.PremiumSub[index].value!=fm.PremiumSub[index].title)
	      {
	        fm.ItemKindSub_Flag[index].value = "U";
	      }
	      else
	      {
	    	  if(fm.ItemKindSub_Flag[index].value != "U") {
	    		  fm.ItemKindSub_Flag[index].value = "";
	    	  }
	      }
    }
  }
}

function setTurnover(){
	if(fm.Turnover.value!=""){
		
		fm.ValueLoss.value=fm.Turnover.value;
		
		
	}else{
		fm.Turnover.value=0.00;
		fm.ValueLoss.value=0.00;
	}
	
}
function setTurnover1(){
	if(fm.Turnover.value!=""){
		fm.ValueLossSub.value=fm.Turnover.value;
	}else{
		fm.Turnover.value=0.00;
		fm.ValueLossSub.value=0.00;
	}
}
//利润损失附加险
function insertItemKindLoss()
{
  var intRowsCount = getRowsCount("ItemKindLoss");
  insertRowForPG('ItemKindLoss','ItemKindLoss_Data');
  
  setcloneNodeEventOfTablePG("ItemKindLoss");
  
  fm.StartDateLoss[intRowsCount+1].value = fm.ValidDate.value;
  fm.EndDateLoss[intRowsCount+1].value = fm.EndDate.value;
  resetItemKindNo(); //该函数在框架的js中
  setItemKindAddressNoLoss();
  //setTurnover();
  //changeTurnover();
  calculatePremiumLoss(fm.ShortRateLoss[intRowsCount+1], 1);
}
//插入第一部分 附加责任险
function insertItemKindLossMainSub()
{
  var intRowsCount = getRowsCount("ItemKindLossMainSub");
  insertRowForPG('ItemKindLossMainSub','ItemKindLossMainSub_Data');
  
  setcloneNodeEventOfTablePG("ItemKindLossMainSub");
  
  fm.StartDateLossMainSub[intRowsCount+1].value = fm.ValidDate.value;
  fm.EndDateLossMainSub[intRowsCount+1].value = fm.EndDate.value;
  resetItemKindNo(); //该函数在框架的js中
  setItemKindAddressNoLoss();
  //setTurnover();
  //changeTurnover();
  calculatePremiumLoss(fm.ShortRateLoss[intRowsCount+1], 1);
}

function deleteItemKindLoss(field,intPageDataKeyCount,intRowsCount)
{
  var index = getElementOrder(field)-1;
  var strFlag = fm.ItemKindLoss_Flag[index].value;
  deleteRowForPG('ItemKindLoss','ItemKindLoss_Data',field,intPageDataKeyCount,intRowsCount);
  resetItemKindNo();
  /*if(fm.RiskCode.value == "6601"||fm.RiskCode.value == "6607"){
  deleteEngage(fm.button_Engage_Delete[1],1,1);
  }*/
  if(strFlag!="I"&&strFlag!="D")
  {
    fm.AmountLoss[index].value = "0.00";
    calculatePremiumLoss(fm.AmountLoss[index],1);
    //setRefreshFlagFeeZero();
  }
}
function deleteItemKindLossMainSub(field,intPageDataKeyCount,intRowsCount)
{
  var index = getElementOrder(field)-1;
  var strFlag = fm.ItemKindLossMainSub_Flag[index].value;
  deleteRowForPG('ItemKindLossMainSub','ItemKindLossMainSub_Data',field,intPageDataKeyCount,intRowsCount);
  resetItemKindNo();
  /*if(fm.RiskCode.value == "6601"||fm.RiskCode.value == "6607"){
  deleteEngage(fm.button_Engage_Delete[1],1,1);
  }*/
  if(strFlag!="I"&&strFlag!="D")
  {
    fm.AmountLossMainSub[index].value = "0.00";
    calculatePremiumLossMainSub(fm.AmountLossMainSub[index],1);
    //setRefreshFlagFeeZero();
  }
}

function getItemKindLoss() {
	var arrayItemKindLossRow = new Array();
	var arrayItemKindLoss = new Array();
	var i = 0;
	var j = 0;
    
	for (i = 1; i <= getRowsCount("ItemKindLoss"); i++) {
		arrayItemKindLossRow = new Array();
       
		arrayItemKindLossRow.KindCode = fm.KindCodeLoss[i].value;
		//alert(getRowsCount("ItemKindLoss"));
		arrayItemKindLossRow.KindName = fm.KindNameLoss[i].value;
		
		// xiaojian_leave：在页面上增加是否算入总保额的隐藏字段，在初始化文件中赋值：PrpDkind.CalculateFlag[1]
		arrayItemKindLossRow.CalculateFlag = fm.CalculateFlagLoss[i].value;
		//arrayItemKindLossRow.CalculateFlag = "Y";
		//arrayItemKindLossRow.ItemCode = fm.ItemCodeLoss[i].value;
		
		//arrayItemKindLossRow.ItemName = fm.ItemNameLoss[i].value;
		//arrayItemKindLossRow.ItemDetailName = fm.ItemDetailNameLoss[i].value;
		arrayItemKindLossRow.Currency = fm.CurrencyLoss[i].value;
		arrayItemKindLossRow.CurrencyName = fm.CurrencyNameLoss[i].value;
		arrayItemKindLossRow.ExchangeRate = parseInt(fm.ExchangeRateLoss[i].value);
		arrayItemKindLossRow.Amount = parseFloat(fm.AmountLoss[i].value.replace(new RegExp(",","g"),""));
		
		arrayItemKindLossRow.Rate = parseFloat(fm.RateLoss[i].value);
		arrayItemKindLossRow.Discount = parseFloat(fm.DiscountLoss[i].value);
		arrayItemKindLossRow.Premium = parseFloat(fm.PremiumLoss[i].value.replace(new RegExp(",","g"),""));
		
		if (isNaN(arrayItemKindLossRow.ExchangeRate))
			arrayItemKindLossRow.ExchangeRate = 0;
		if (isNaN(arrayItemKindLossRow.Amount))
			arrayItemKindLossRow.Amount = 0;
		if (isNaN(arrayItemKindLossRow.Rate))
			arrayItemKindLossRow.Rate = 0;
		if (isNaN(arrayItemKindLossRow.Discount))
			arrayItemKindLossRow.Discount = 0;
		if (isNaN(arrayItemKindLossRow.Premium))
			arrayItemKindLossRow.Premium = 0;
         
		arrayItemKindLoss[arrayItemKindLoss.length] = arrayItemKindLossRow; // 一个标的信息
	}
	
	return arrayItemKindLoss;
}

function getItemKindLossMainSub() {
	var arrayItemKindLossMainSubRow = new Array();
	var arrayItemKindLossMainSub = new Array();
	var i = 0;
	var j = 0;
    
	for (i = 1; i <= getRowsCount("ItemKindLossMainSub"); i++) {
		arrayItemKindLossMainSubRow = new Array();
       
		arrayItemKindLossMainSubRow.KindCode = fm.KindCodeLossMainSub[i].value;
		//alert(getRowsCount("ItemKindLossMainSub"));
		arrayItemKindLossMainSubRow.KindName = fm.KindNameLossMainSub[i].value;
		
		// xiaojian_leave：在页面上增加是否算入总保额的隐藏字段，在初始化文件中赋值：PrpDkind.CalculateFlag[1]
		arrayItemKindLossMainSubRow.CalculateFlag = fm.CalculateFlagLossMainSub[i].value;
		//arrayItemKindLossMainSubRow.CalculateFlag = "Y";
		//arrayItemKindLossMainSubRow.ItemCode = fm.ItemCodeLossMainSub[i].value;
		
		//arrayItemKindLossMainSubRow.ItemName = fm.ItemNameLossMainSub[i].value;
		//arrayItemKindLossMainSubRow.ItemDetailName = fm.ItemDetailNameLossMainSub[i].value;
		arrayItemKindLossMainSubRow.Currency = fm.CurrencyLossMainSub[i].value;
		arrayItemKindLossMainSubRow.CurrencyName = fm.CurrencyNameLossMainSub[i].value;
		arrayItemKindLossMainSubRow.ExchangeRate = parseInt(fm.ExchangeRateLossMainSub[i].value);
		arrayItemKindLossMainSubRow.Amount = parseFloat(fm.AmountLossMainSub[i].value.replace(new RegExp(",","g"),""));
		
		arrayItemKindLossMainSubRow.Rate = parseFloat(fm.RateLossMainSub[i].value);
		arrayItemKindLossMainSubRow.Discount = parseFloat(fm.DiscountLossMainSub[i].value);
		arrayItemKindLossMainSubRow.Premium = parseFloat(fm.PremiumLossMainSub[i].value.replace(new RegExp(",","g"),""));
		
		if (isNaN(arrayItemKindLossMainSubRow.ExchangeRate))
			arrayItemKindLossMainSubRow.ExchangeRate = 0;
		if (isNaN(arrayItemKindLossMainSubRow.Amount))
			arrayItemKindLossMainSubRow.Amount = 0;
		if (isNaN(arrayItemKindLossMainSubRow.Rate))
			arrayItemKindLossMainSubRow.Rate = 0;
		if (isNaN(arrayItemKindLossMainSubRow.Discount))
			arrayItemKindLossMainSubRow.Discount = 0;
		if (isNaN(arrayItemKindLossMainSubRow.Premium))
			arrayItemKindLossMainSubRow.Premium = 0;
         
		arrayItemKindLossMainSub[arrayItemKindLossMainSub.length] = arrayItemKindLossMainSubRow; // 一个标的信息
	}
	
	return arrayItemKindLossMainSub;
}



function getItemKindLoss6603() {
	var arrayItemKindLossRow = new Array();
	var arrayItemKindLoss = new Array();
	var i = 0;
	var j = 0;
    
	for (i = 1; i <= getRowsCount("ItemKindLoss"); i++) {
		arrayItemKindLossRow = new Array();
       
		arrayItemKindLossRow.KindCode = fm.KindCodeLoss[i].value;
		//alert(getRowsCount("ItemKindLoss"));
		arrayItemKindLossRow.KindName = fm.KindNameLoss[i].value;
		
		// xiaojian_leave：在页面上增加是否算入总保额的隐藏字段，在初始化文件中赋值：PrpDkind.CalculateFlag[1]
		arrayItemKindLossRow.CalculateFlag = fm.CalculateFlagLoss[i].value;
		//arrayItemKindLossRow.CalculateFlag = "Y";
		//arrayItemKindLossRow.ItemCode = fm.ItemCodeLoss[i].value;
		
		//arrayItemKindLossRow.ItemName = fm.ItemNameLoss[i].value;
		//arrayItemKindLossRow.ItemDetailName = fm.ItemDetailNameLoss[i].value;
		arrayItemKindLossRow.Currency = fm.CurrencyLoss[i].value;
		arrayItemKindLossRow.CurrencyName = fm.CurrencyNameLoss[i].value;
		arrayItemKindLossRow.ExchangeRate = fm.ExchangeRateLoss[i].value;
		arrayItemKindLossRow.Amount = parseFloat(fm.AmountLoss[i].value);/**changuish**/
		//if(fm.RiskCode.value == "6603")arrayItemKindLossRow.Amount = parseFloat(fm.TurnoverLoss[i].value);/**chaguish**/
		arrayItemKindLossRow.Rate = parseFloat(fm.RateLoss[i].value);
		arrayItemKindLossRow.Discount = parseFloat(fm.DiscountLoss[i].value);
		arrayItemKindLossRow.Premium = parseFloat(fm.PremiumLoss[i].value);

		if (isNaN(arrayItemKindLossRow.ExchangeRate))
			arrayItemKindLossRow.ExchangeRate = 0;
		if (isNaN(arrayItemKindLossRow.Amount))
			arrayItemKindLossRow.Amount = 0;
		if (isNaN(arrayItemKindLossRow.Rate))
			arrayItemKindLossRow.Rate = 0;
		if (isNaN(arrayItemKindLossRow.Discount))
			arrayItemKindLossRow.Discount = 0;
		if (isNaN(arrayItemKindLossRow.Premium))
			arrayItemKindLossRow.Premium = 0;
         
		arrayItemKindLoss[arrayItemKindLoss.length] = arrayItemKindLossRow; // 一个标的信息
	}
	
	return arrayItemKindLoss;
}

function getOldItemKindLoss()
{
  var arrayItemKindLossRow = new Array();
  var arrayItemKindLoss = new Array();
  var i = 0;
  var j = 0;

  for(i=1;i<=getRowsCount("ItemKindLoss");i++)
  {
    arrayItemKindLossRow = new Array();

    arrayItemKindLossRow.KindCode = fm.KindCodeLoss[i].title;
    arrayItemKindLossRow.KindName = fm.KindNameLoss[i].title;
    //xiaojian_leave：在页面上增加是否算入总保额的隐藏字段，在初始化文件中赋值：PrpDkind.CalculateFlag[1]
    arrayItemKindLossRow.CalculateFlag = fm.CalculateFlagLoss[i].title;
    //arrayItemKindLossRow.CalculateFlag = "Y";
    //arrayItemKindLossRow.ItemCode = fm.ItemCodeLoss[i].title;
    //arrayItemKindLossRow.ItemName = fm.ItemNameLoss[i].title;
    //arrayItemKindLossRow.ItemDetailName = fm.ItemDetailNameLoss[i].title;
    arrayItemKindLossRow.Currency = fm.CurrencyLoss[i].title;
    arrayItemKindLossRow.CurrencyName = fm.CurrencyNameLoss[i].title;
    arrayItemKindLossRow.ExchangeRate = fm.ExchangeRateLoss[i].title;
    arrayItemKindLossRow.Amount = parseFloat(fm.AmountLoss[i].title);
    arrayItemKindLossRow.Rate = parseFloat(fm.RateLoss[i].title);
    arrayItemKindLossRow.Discount = parseFloat(fm.DiscountLoss[i].title);
    arrayItemKindLossRow.Premium = parseFloat(fm.PremiumLoss[i].title);

    if(isNaN(arrayItemKindLossRow.ExchangeRate))
      arrayItemKindLossRow.ExchangeRate = 0;
    if(isNaN(arrayItemKindLossRow.Amount))
      arrayItemKindLossRow.Amount = 0;
    if(isNaN(arrayItemKindLossRow.Rate))
      arrayItemKindLossRow.Rate = 0;
    if(isNaN(arrayItemKindLossRow.Discount))
      arrayItemKindLossRow.Discount = 0;
    if(isNaN(arrayItemKindLossRow.Premium))
      arrayItemKindLossRow.Premium = 0;

    arrayItemKindLoss[arrayItemKindLoss.length] = arrayItemKindLossRow; //一个标的信息
  }

  return arrayItemKindLoss;
}

function getOldItemKindLossMainSub()
{
  var arrayItemKindLossMainSubRow = new Array();
  var arrayItemKindLossMainSub = new Array();
  var i = 0;
  var j = 0;

  for(i=1;i<=getRowsCount("ItemKindLossMainSub");i++)
  {
    arrayItemKindLossMainSubRow = new Array();

    arrayItemKindLossMainSubRow.KindCode = fm.KindCodeLossMainSub[i].title;
    arrayItemKindLossMainSubRow.KindName = fm.KindNameLossMainSub[i].title;
    //xiaojian_leave：在页面上增加是否算入总保额的隐藏字段，在初始化文件中赋值：PrpDkind.CalculateFlag[1]
    arrayItemKindLossMainSubRow.CalculateFlag = fm.CalculateFlagLossMainSub[i].title;
    //arrayItemKindLossMainSubRow.CalculateFlag = "Y";
    //arrayItemKindLossMainSubRow.ItemCode = fm.ItemCodeLossMainSub[i].title;
    //arrayItemKindLossMainSubRow.ItemName = fm.ItemNameLossMainSub[i].title;
    //arrayItemKindLossMainSubRow.ItemDetailName = fm.ItemDetailNameLossMainSub[i].title;
    arrayItemKindLossMainSubRow.Currency = fm.CurrencyLossMainSub[i].title;
    arrayItemKindLossMainSubRow.CurrencyName = fm.CurrencyNameLossMainSub[i].title;
    arrayItemKindLossMainSubRow.ExchangeRate = fm.ExchangeRateLossMainSub[i].title;
    arrayItemKindLossMainSubRow.Amount = parseFloat(fm.AmountLossMainSub[i].title);
    arrayItemKindLossMainSubRow.Rate = parseFloat(fm.RateLossMainSub[i].title);
    arrayItemKindLossMainSubRow.Discount = parseFloat(fm.DiscountLossMainSub[i].title);
    arrayItemKindLossMainSubRow.Premium = parseFloat(fm.PremiumLossMainSub[i].title);

    if(isNaN(arrayItemKindLossMainSubRow.ExchangeRate))
      arrayItemKindLossMainSubRow.ExchangeRate = 0;
    if(isNaN(arrayItemKindLossMainSubRow.Amount))
      arrayItemKindLossMainSubRow.Amount = 0;
    if(isNaN(arrayItemKindLossMainSubRow.Rate))
      arrayItemKindLossMainSubRow.Rate = 0;
    if(isNaN(arrayItemKindLossMainSubRow.Discount))
      arrayItemKindLossMainSubRow.Discount = 0;
    if(isNaN(arrayItemKindLossMainSubRow.Premium))
      arrayItemKindLossMainSubRow.Premium = 0;

    arrayItemKindLossMainSub[arrayItemKindLossMainSub.length] = arrayItemKindLossMainSubRow; //一个标的信息
  }

  return arrayItemKindLossMainSub;
}
function getCollectItemKindLoss()
{
  var arrayItemKindLoss = new Array();
  return arrayItemKindLoss;
}
function getCollectItemKindLossMainSub()
{
  var arrayItemKindLossMainSub = new Array();
  return arrayItemKindLossMainSub;
}

function calculatePremiumLoss(field,strCalculateShortRateFlag)
{
  var index = getElementOrder(field)-1;
  //if(parseInt(strCalculateShortRateFlag,10)==1)
    fm.all("ShortRateLoss")[index].value = pointFour(round(calShortRate(index,"Loss"),4));
  fm.all("PremiumLoss")[index].value = pointTwo(round(formulizePremium(index,"Loss"),2));
  setRefreshFlagFeeZero();
}
function calculatePremiumLossMainSub(field,strCalculateShortRateFlag)
{
  var index = getElementOrder(field)-1;
  //if(parseInt(strCalculateShortRateFlag,10)==1)
    fm.all("ShortRateLossMainSub")[index].value = pointFour(round(calShortRate(index,"LossMainSub"),4));
  fm.all("PremiumLossMainSub")[index].value = pointTwo(round(formulizePremium(index,"LossMainSub"),2));
  setRefreshFlagFeeZero();
}

function calculatePremiumLossMainSub(field,strCalculateShortRateFlag)
{
  var index = getElementOrder(field)-1;
  //if(parseInt(strCalculateShortRateFlag,10)==1)
    fm.all("ShortRateLossMainSub")[index].value = pointFour(round(calShortRate(index,"LossMainSub"),4));
  fm.all("PremiumLossMainSub")[index].value = pointTwo(round(formulizePremium(index,"LossMainSub"),2));
  setRefreshFlagFeeZero();
}
function calculatePremiumLossOnlyZero(field,strCalculateShortRateFlag)
{
  if(field.value==""&&parseFloat(field.value)!=0)
    return;
  calculatePremiumLoss(field,strCalculateShortRateFlag);
}
function calculatePremiumLossMainSubOnlyZero(field,strCalculateShortRateFlag)
{
  if(field.value==""&&parseFloat(field.value)!=0)
    return;
  calculatePremiumLossMainSub(field,strCalculateShortRateFlag);
}
function setSumAmountPremiumToItemKindLoss(dbSumAmountLoss,dbSumPremiumLoss)
{
  fm.SumAmountLoss.value = pointTwo(round(dbSumAmountLoss,2));
  fm.CurrencySumAmountLoss.value = fm.Currency2Fee.value
  fm.CurrencyNameSumAmountLoss.value = fm.CurrencyName2Fee.value;
  fm.SumPremiumLoss.value = pointTwo(round(dbSumPremiumLoss,2));
  fm.CurrencySumPremiumLoss.value = fm.Currency2Fee.value
  fm.CurrencyNameSumPremiumLoss.value = fm.CurrencyName2Fee.value;
}
function setSumAmountPremiumToItemKindLossMainSub(dbSumAmountLossMainSub,dbSumPremiumLossMainSub)
{
  fm.SumAmountLossMainSub.value = pointTwo(round(dbSumAmountLossMainSub,2));
  fm.CurrencySumAmountLossMainSub.value = fm.Currency2Fee.value
  fm.CurrencyNameSumAmountLossMainSub.value = fm.CurrencyName2Fee.value;
  fm.SumPremiumLossMainSub.value = pointTwo(round(dbSumPremiumLossMainSub,2));
  fm.CurrencySumPremiumLossMainSub.value = fm.Currency2Fee.value
  fm.CurrencyNameSumPremiumLossMainSub.value = fm.CurrencyName2Fee.value;
}
function checkItemKindLoss()
{
  var intRowsCount = getRowsCount("ItemKindLoss");
  var i = 0;
  
  var result =true;
  var resulttemp =true;
  var AllMessage="主险信息模块校验不通过，请关注红色录入域,重新填写正确的保单信息\n";
  //校验之前如果没展开的话先打开，校验没有问题后关闭掉
  elements =document.getElementsByName( "ItemKindLossImg");
  openPage(elements[0],ItemKindLoss);
  var arryList= ['KindCodeLoss','KindNameLoss','CurrencyLoss','ValueLoss','LIMITTYPE04Main','LIMITTYPE01Main','LIMITTYPE03Main','LIMITTYPE07Main','LIMITTYPE02Main','LIMITTYPE24Main','LIMITTYPE08Main','LIMITTYPE12Main','FamilyNameLoss','RateLoss','PremiumLoss'];
  if(!fm.chkKindLoss.checked&&intRowsCount>0)
  {
    showPageOnly(document.ItemKindLossImg,ItemKindLoss); //在UICommon.js中，只是显示并没有隐藏作用的函数
    //errorMessage("没有选中投保责任险，不能有责任险附加险的信息！");
    showMessage("chkKindLoss", "没有选中投保责任险，不能有责任险附加险的信息！", "red","");
    //fm.chkKindLoss.focus();
    checkKindLoss(fm.chkKindLoss);
    return false;
  }
  for(i=1;i<=intRowsCount;i++)
  {
  	resulttemp = saveMessageValid(i,arryList,"");
	 if(resulttemp==false){
		 result =false;
		 }	
  }
  if(result==false){
      
      setcrollTo(elements[0]);
      ErrAllMessage(AllMessage);
      
  return  false;
  }
  setFlagPG('ItemKindLoss',2);
  setItemKindLossPropFlagPG();
  setItemKindMainLimitFlagPG();    
  closePage(elements[0],ItemKindLoss);
  return true;
}
function checkItemKindLossMainSub()
{
  var intRowsCount = getRowsCount("ItemKindLossMainSub");
  var i = 0;
  
  var result =true;
  var resulttemp =true;
  var AllMessage="主险信息模块校验不通过，请关注红色录入域,重新填写正确的保单信息\n";
  //校验之前如果没展开的话先打开，校验没有问题后关闭掉
  elements =document.getElementsByName( "ItemKindLossMainSubImg");
  openPage(elements[0],ItemKindLossMainSub);
  var arryList= ['KindCodeLossMainSub','KindNameLossMainSub','CurrencyLossMainSub','ValueLossMainSub','LIMITTYPE90Sub','LIMITTYPE91Sub','LIMITTYPE92Sub','LIMITTYPE93Sub','LIMITTYPE94Sub','LIMITTYPE95Sub','LIMITTYPE96Sub','LIMITTYPE97Sub','FamilyNameLossMainSub','RateLossMainSub','PremiumLossMainSub'];
  if(!fm.chkKindLossMainSub.checked&&intRowsCount>0)
  {
    showPageOnly(document.ItemKindLossMainSubImg,ItemKindLossMainSub); //在UICommon.js中，只是显示并没有隐藏作用的函数
    //errorMessage("没有选中投保责任险，不能有责任险附加险的信息！");
    showMessage("chkKindLossMainSub", "没有选中投保责任险，不能有责任险附加险的信息！", "red","");
    //fm.chkKindLossMainSub.focus();
    checkKindLossMainSub(fm.chkKindLossMainSub);
    return false;
  }
  for(i=1;i<=intRowsCount;i++)
  {
  	resulttemp = saveMessageValid(i,arryList,"");
	 if(resulttemp==false){
		 result =false;
		 }	
  }
  if(result==false){
      
      setcrollTo(elements[0]);
      ErrAllMessage(AllMessage);
      
  return  false;
  }
  setFlagPG('ItemKindLossMainSub',2);
  setItemKindLossMainSubPropFlagPG();
  setItemKindMainLimitFlagPG();    
  closePage(elements[0],ItemKindLossMainSub);
  return true;
}


//modify by lianjingwei 都邦项目组 应该判断不同情况存放标志位，不应该都放U. 2006-02-17 17:47 start<----
function setItemKindLossPropFlagPG()
{  
	if(fm.GrossProfitMonths.title =="" && fm.WageMonths.title=="" ){
  	   if(fm.GrossProfitMonths.value!=fm.GrossProfitMonths.title||
     	  fm.WageMonths.value!=fm.WageMonths.title
     	  )
  	   {
   		   fm.ItemKindLossItemProp_Flag.value = "I";
     	}
	}else{
		if(fm.GrossProfitMonths.value==""&&fm.WageMonths.value==""){
		fm.ItemKindLossItemProp_Flag.value = "D";
		}
		else{
			fm.ItemKindLossItemProp_Flag.value = "U";
		}
	}
}
function setItemKindLossMainSubPropFlagPG()
{  
	
}
//modify by lianjingwei 都邦项目组 应该判断不同情况存放标志位，不应该都放U. 2006-02-17 17:47 end---->
function checkItemKindLossMainSub()
{
  var intRowsCount = getRowsCount("ItemKindLossMainSub");
  var i = 0;
  
  var result =true;
  var resulttemp =true;
  var AllMessage="主险信息模块校验不通过，请关注红色录入域,重新填写正确的保单信息\n";
  //校验之前如果没展开的话先打开，校验没有问题后关闭掉
  elements =document.getElementsByName( "ItemKindLossMainSubImg");
  openPage(elements[0],ItemKindLossMainSub);
  var arryList= ['KindCodeLossMainSub','KindNameLossMainSub','CurrencyLossMainSub','ValueLossMainSub','LIMITTYPE90Sub','LIMITTYPE91Sub','LIMITTYPE92Sub','LIMITTYPE93Sub','LIMITTYPE94Sub','LIMITTYPE95Sub','LIMITTYPE96Sub','LIMITTYPE97Sub','FamilyNameLossMainSub','RateLossMainSub','PremiumLossMainSub'];
  if(!fm.chkKindLossMainSub.checked&&intRowsCount>0)
  {
    showPageOnly(document.ItemKindLossMainSubImg,ItemKindLossMainSub); //在UICommon.js中，只是显示并没有隐藏作用的函数
    //errorMessage("没有选中投保责任险，不能有责任险附加险的信息！");
    showMessage("chkKindLossMainSub", "没有选中投保责任险，不能有责任险附加险的信息！", "red","");
    //fm.chkKindLossMainSubMainSub.focus();
    checkKindLossMainSub(fm.chkKindLossMainSub);
    return false;
 // }
  for(i=1;i<=intRowsCount;i++)
  {
  	resulttemp = saveMessageValid(i,arryList,"");
	 if(resulttemp==false){
		 result =false;
		 }	
  }
  if(result==false){
      
      setcrollTo(elements[0]);
      ErrAllMessage(AllMessage);
      
  return  false;
  }
  setFlagPG('ItemKindLossMainSub',2);
  setItemKindLossMainSubPropFlagPG();
  setItemKindMainLimitFlagPG();    
  closePage(elements[0],ItemKindLossMainSub);
  return true;
}


//利润损失附加险附加条款
function insertItemKindLossSub()
{
  var intRowsCount = getRowsCount("ItemKindLossSub");
  
  insertRowForPG('ItemKindLossSub','ItemKindLossSub_Data');
  
  setcloneNodeEventOfTablePG("ItemKindLossSub");
  
  fm.StartDateLossSub[intRowsCount+1].value = fm.ValidDate.value;
  fm.EndDateLossSub[intRowsCount+1].value = fm.EndDate.value;
  resetItemKindNo(); //该函数在框架的js中
  calculatePremiumLossSub(fm.ShortRateLossSub[intRowsCount+1], 1);
  /*if(fm.RiskCode.value == "6606"){
		fm.KindCodeLossSub[intRowsCount + 1].value = "0404";
		fm.KindCodeLossSub[intRowsCount + 1].ondblclick = null;
		fm.KindCodeLossSub[intRowsCount + 1].onblur = null;
		fm.KindCodeLossSub[intRowsCount + 1].onkeyup = null;
		fm.KindCodeLossSub[intRowsCount + 1].onchannge = null;
		fm.KindCodeLossSub[intRowsCount + 1].readOnly = true;
		fm.KindNameLossSub[intRowsCount + 1].value = "附加非房主居住责任保险";
		fm.KindNameLossSub[intRowsCount + 1].ondblclick = null;
		fm.KindNameLossSub[intRowsCount + 1].onblur = null;
		fm.KindNameLossSub[intRowsCount + 1].onkeyup = null;
		fm.KindNameLossSub[intRowsCount + 1].onchange = null;
		fm.KindNameLossSub[intRowsCount + 1].readOnly = true;
		fm.AmountLossSub[intRowsCount + 1].value="400000.00";//保额
		fm.AmountLossSub[intRowsCount + 1].readOnly = true;
		fm.RateLossSub[intRowsCount + 1].value = 158/400000*1000;//费率
		fm.RateLossSub[intRowsCount + 1].readOnly = true;//费率
		fm.PremiumLossSub[intRowsCount + 1].value="158.00";//保费
		fm.PremiumLossSub[intRowsCount + 1].readOnly = true;
		fm.DeductibleUnitLossSub[intRowsCount + 1].value="无免赔";//免赔
		fm.DeductibleUnitLossSub[intRowsCount + 1].readOnly=true;//免赔
		fm.DeductibleUnitLossSub[intRowsCount + 1].ondblclick = null;
		fm.DeductibleUnitLossSub[intRowsCount + 1].onblur = null;
		fm.DeductibleUnitLossSub[intRowsCount + 1].onkeyup = null;
		fm.AmountLossSubselect[intRowsCount + 1].style.display = "none";
	}*/
}

function deleteItemKindLossSub(field,intPageDataKeyCount,intRowsCount)
{
  var index = getElementOrder(field)-1;
  var strFlag = fm.ItemKindLossSub_Flag[index].value;
  deleteRowForPG('ItemKindLossSub','ItemKindLossSub_Data',field,intPageDataKeyCount,intRowsCount);
  resetItemKindNo();
  if(strFlag!="I"&&strFlag!="D")
  {
    fm.AmountLossSub[index].value = "0.00";
    calculatePremiumLossSub(fm.AmountLossSub[index],1);
    //setRefreshFlagFeeZero();
  }
}

function getItemKindLossSub()
{
  var arrayItemKindLossSubRow = new Array();
  var arrayItemKindLossSub = new Array();
  var i = 0;
  var j = 0;

  for(i=1;i<=getRowsCount("ItemKindLossSub");i++)
  {
    arrayItemKindLossSubRow = new Array();

    arrayItemKindLossSubRow.KindCode = fm.KindCodeLossSub[i].value;
    arrayItemKindLossSubRow.KindName = fm.KindNameLossSub[i].value;
    //xiaojian_leave：在页面上增加是否算入总保额的隐藏字段，在初始化文件中赋值：PrpDkind.CalculateFlag[1]
    arrayItemKindLossSubRow.CalculateFlag = fm.CalculateFlagLossSub[i].value;
    //arrayItemKindLossSubRow.CalculateFlag = "N";
    arrayItemKindLossSubRow.ItemCode = fm.ItemCodeLossSub[i].value;
    arrayItemKindLossSubRow.Currency = fm.CurrencyLossSub[i].value;
    arrayItemKindLossSubRow.CurrencyName = fm.CurrencyNameLossSub[i].value;
    arrayItemKindLossSubRow.ExchangeRate = fm.ExchangeRateLossSub[i].value;
    arrayItemKindLossSubRow.Amount = parseFloat(fm.AmountLossSub[i].value);
    arrayItemKindLossSubRow.Rate = parseFloat(fm.RateLossSub[i].value);
    arrayItemKindLossSubRow.Discount = parseFloat(fm.DiscountLossSub[i].value);
    arrayItemKindLossSubRow.Premium = parseFloat(fm.PremiumLossSub[i].value);

    if(isNaN(arrayItemKindLossSubRow.ExchangeRate))
      arrayItemKindLossSubRow.ExchangeRate = 0;
    if(isNaN(arrayItemKindLossSubRow.Amount))
      arrayItemKindLossSubRow.Amount = 0;
    if(isNaN(arrayItemKindLossSubRow.Rate))
      arrayItemKindLossSubRow.Rate = 0;
    if(isNaN(arrayItemKindLossSubRow.Discount))
      arrayItemKindLossSubRow.Discount = 0;
    if(isNaN(arrayItemKindLossSubRow.Premium))
      arrayItemKindLossSubRow.Premium = 0;

    arrayItemKindLossSub[arrayItemKindLossSub.length] = arrayItemKindLossSubRow; //一个标的信息
  }

  return arrayItemKindLossSub;
}

function getOldItemKindLossSub()
{
  var arrayItemKindLossSub = new Array();
  return arrayItemKindLossSub;
}

function getCollectItemKindLossSub()
{
  var arrayItemKindLossSub = new Array();
  return arrayItemKindLossSub;
}

function calculatePremiumLossSub(field,strCalculateShortRateFlag)
{
  var index = getElementOrder(field)-1;
  //if(parseInt(strCalculateShortRateFlag,10)==1)
    fm.all("ShortRateLossSub")[index].value = pointFour(round(calShortRate(index,"LossSub"),4));
  fm.all("PremiumLossSub")[index].value = pointTwo(round(formulizePremium(index,"LossSub"),2));
  setRefreshFlagFeeZero();
}

function calculatePremiumLossSubOnlyZero(field,strCalculateShortRateFlag)
{
  if(field.value==""&&parseFloat(field.value)!=0)
    return;
  calculatePremiumLossSub(field,strCalculateShortRateFlag);
}

function setSumAmountPremiumToItemKindLossSub(dbSumAmountLossSub,dbSumPremiumLossSub)
{
  fm.SumAmountLossSub.value = pointTwo(round(dbSumAmountLossSub,2));
  fm.CurrencySumAmountLossSub.value = fm.Currency2Fee.value
  fm.CurrencyNameSumAmountLossSub.value = fm.CurrencyName2Fee.value;
  fm.SumPremiumLossSub.value = pointTwo(round(dbSumPremiumLossSub,2));
  fm.CurrencySumPremiumLossSub.value = fm.Currency2Fee.value
  fm.CurrencyNameSumPremiumLossSub.value = fm.CurrencyName2Fee.value;
}

function checkItemKindLossSub()
{
  var intRowsCount = getRowsCount("ItemKindLossSub");
  var i = 0;
  var result =true;
  var resulttemp =true;
  var AllMessage="附加险信息模块校验不通过，请关注红色录入域,重新填写正确的保单信息\n";
  //校验之前如果没展开的话先打开，校验没有问题后关闭掉
  elements =document.getElementsByName( "ItemKindLossSubImg");
  openPage(elements[0],ItemKindLossSub);
  var arryList = ['KindCodeLossSub','KindNameLossSub','CurrencyLossSub','AmountLossSub','UnitAmountLossSub','ValueLossSub','FamilyNameLossSub','RateLossSub','PremiumLossSub'];
  for(i=1;i<=intRowsCount;i++)
  {
  resulttemp = saveMessageValid(i,arryList,"");
	 if(resulttemp==false){
		 result =false;
		 }	
  }
  if(result==false){
      
      setcrollTo(elements[0]);
      ErrAllMessage(AllMessage);
      
  return  false;
  }
  for(i=1;i<=intRowsCount;i++)
  {
	  for (j = i + 1; j <= intRowsCount; j++) {
			if (fm.KindCodeLossSub[i].value == fm.KindCodeLossSub[j].value) {
				errorMessage(fm.KindCodeLossSub[i].description + "不能重复录入！");
				showPageOnly(document.ItemKindLossSubImg, ItemKindLossSub);
				fm.KindCodeLossSub[i].focus();
				return false;
			}
		}
  }
  if(CheckThisSubRiskAmount() == false){
		return false;
	}
  setFlagPG('ItemKindLossSub',2);
  setItemKindLossSubEngageFlagPG();
  setItemKindLossSubDetailEngage_FlagPG();
  closePage(elements[0],ItemKindLossSub);
  return true;
}

function setItemKindLossSubEngageFlagPG()
{
  var index = 0;
  for(index=1;index<=getRowsCount("ItemKindLossSub");index++)
  {
    fm.ItemKindLossSubEngage_Flag[index].value = "";
    if(fm.ItemKindLossSub_Flag[index].value!="U")
    {
      fm.ItemKindLossSubEngage_Flag[index].value = fm.ItemKindLossSub_Flag[index].value;
    }
    else
    {
      if(fm.ItemKindLossSub_Context[index].value!=fm.ItemKindLossSub_Context[index].title)
      {
        fm.ItemKindLossSubEngage_Flag[index].value = "U";
      }
      if(fm.DeductibleRateLossSub[index].value!=fm.DeductibleRateLossSub[index].title||
         
         fm.ShortRateFlagLossSub[index].value!=fm.ShortRateFlagLossSub[index].title||
         fm.ShortRateLossSub[index].value!=fm.ShortRateLossSub[index].title||
         fm.KindCodeLossSub[index].value!=fm.KindCodeLossSub[index].title||
         fm.KindNameLossSub[index].value!=fm.KindNameLossSub[index].title||
         //fm.ItemNameLossSub[index].value!=fm.ItemNameLossSub[index].title||
         //fm.ItemDetailNameLossSub[index].value!=fm.ItemDetailNameLossSub[index].title||
         fm.CurrencyLossSub[index].value!=fm.CurrencyLossSub[index].title||
         fm.AmountLossSub[index].value!=fm.AmountLossSub[index].title||
         fm.RateLossSub[index].value!=fm.RateLossSub[index].title||
         fm.PremiumLossSub[index].value!=fm.PremiumLossSub[index].title)
      {
        fm.ItemKindLossSub_Flag[index].value = "U";
      }
      else
      {
        //fm.ItemKindLossSub_Flag[index].value = "";
      }
    }
  }
}

//公共
function setItemKindEngage(field,strFlag1,strFlag2)
{
  var strClauseCode = "";
  var strClauseName = "";
  var strClausesContext = "";
  var intRowsCount = getRowsCount("Engage");
  var index = -1;
  var i = 0;

  if(strFlag2=="Deductible")
  {
    if(strFlag1=="Main")
    {
      strClauseCode = "TX001";
      strClauseName = "每次事故绝对免赔";
      //add by wuxiaodong 051117 begain reasion 如果删除免赔信息时自动将特约中的免赔删除
      if(fm.DeductibleTextMain.value=="")
      {
      	deleteDeductibleTextEngage(strFlag1);
      	intRowsCount = getRowsCount("Engage");
      	return;
      }
      //add by wuxiaodong 051117 end
    }
    else if(strFlag1=="Loss")
    {
      strClauseCode = "TX002";
      strClauseName = "利润损失附加险每次事故绝对免赔";
       //add by wuxiaodong 051117 begain reasion 如果删除免赔信息时自动将特约中的免赔删除
      if(fm.DeductibleTextLoss.value=="")
      {
      	deleteDeductibleTextEngage(strFlag1);
      	intRowsCount = getRowsCount("Engage");
      	return;
      }
    }

    for(i=intRowsCount;i>=1;i--)
    {
      if(fm.ClauseCode[i].value==strClauseCode)
      {
        if(fm.Engage_Flag[i].value!="I"&&index<0)
        {
          index = i;
          if(fm.Engage_Flag[i].value=="D")
            deleteEngage(fm.button_Engage_Delete[index],1,1);
        }
        else
        {
          //modify by wuxiaodong 051110 reasion 此时index为-1导致button的值找不到
          //deleteEngage(fm.button_Engage_Delete[index],1,1);
          deleteEngage(fm.button_Engage_Delete[i],1,1);
        }
      }
    }
    if(index==-1) //原来没有相关的特别约定
    {
      if(trim(field.value).length>0)
      {
        //insert
        setBackColor(field,BGCOLORI);
        intRowsCount = getRowsCount("Engage");
        insertRowForPG('Engage','Engage_Data');
        fm.ClauseCode[intRowsCount+1].value = strClauseCode;
        fm.Clauses[intRowsCount+1].value = strClauseName;
        fm.ClausesContext[intRowsCount+1].value = field.value;
        setReadonlyOfElement(fm.ClauseCode[intRowsCount+1]);
        setReadonlyOfElement(fm.Clauses[intRowsCount+1]);
        setReadonlyOfElement(fm.ClausesContext[intRowsCount+1]);
        setReadonlyOfElement(fm.button_Engage_Delete[intRowsCount+1]);
        
        if (strClauseCode == "TX001") {
			enage_id[intRowsCount + 1].style.display = "none";	//隐藏此行
		} else if (strClauseCode == "TX002") {
			enage_id[intRowsCount + 1].style.display = "none";	//隐藏此行
		}
      }
    }
    else if(index>0) //原来有相关的特别约定
    {
      if(trim(field.value).length>0)
      {
        //update
        setBackColor(field,BGCOLORU);
        fm.ClausesContext[index].value = field.value;
      }
      else
      {
        //delete
        setBackColor(field,BGCOLORD);
        fm.ClausesContext[index].value = field.title;
        deleteEngage(fm.button_Engage_Delete[index],1,1);
      }
    }
    try
    {
      fm.ClausesContext[index].onchange();
    }catch(e){}
  }
}

function checkKindLossChecked(field)
{
  var bChecked = "";

  if(field.name=="ItemKindLossImg")
  {
    if(!fm.chkKindLoss.checked)
    {
      //errorMessage("投保责任险，必须先选中责任险！");
      showMessage("chkKindLoss", "投保责任险，必须先选中责任险！", "red","");
      //fm.chkKindLoss.focus();
      return false;
    }

    showPage(field,ItemKindLoss);
    return true;
  }
  else if(field.name=="ItemKindLossSubImg")
  {
    if(fm.chkKindLoss.checked)
    {
      if(getRowsCount("ItemKindLoss")<=0)
      {
        errorMessage("投保责任险附加条款，必须先投保责任险！");
        showPageOnly(document.ItemKindLossImg,ItemKindLoss);
        return false;
      }
    }
    else
    {
      //errorMessage("投保责任险附加险附加条款，必须先选中责任险！");
      showMessage("chkKindLoss", "投保责任险附加险附加条款，必须先选中责任险", "red","");
      //fm.chkKindLoss.focus();
      return false;
    }

    showPage(field,ItemKindLossSub);
    return true;
  }
}

function checkKindLoss(field)
{
	var strRiskCode = fm.RiskCode.value;
  if(!field.checked)
  {

    for(var i=1;i<fm.ItemCodeLoss.length;i++)
    {
      if(fm.ItemKindLoss_Flag[i].value!="D")
      {
        alert("请先删除责任险下的所有标的");
        field.checked=true;
        return false;
      }
    }
    for(var i=1;i<fm.KindCodeLossSub.length;i++)
    {
      if(fm.ItemKindLossSub_Flag[i].value!="D")
      {
        alert("请先删除责任险下的所有标的");
        field.checked=true;
        return false;
      }
    }

//    deleteAllRows("ItemKindLoss");
    fm.DeductibleTextLoss.value = "";
//    deleteDeductibleTextEngage("Loss");
    fm.GrossProfitMonths.value = "";
    fm.WageMonths.value = "";
  //  fm.WageHeadWeeks.value = "";
    ItemKindLoss.style.display = "none";
    fm.ItemKindLossImg.src="/prpall/commonship/images/butCollapse.gif";
//    deleteAllRows("ItemKindLossSub");
    ItemKindLossSub.style.display = "none";
    fm.ItemKindLossSubImg.src="/prpall/commonship/images/butCollapse.gif";

   }
  
}

function showItemKindContext(field,strFlag)
{
  var strQueryString = "";
  var strSpanName = "span_ItemKind"+strFlag+"_Context";
  var index = getElementOrder(field)-1;

  if(!isEmpty(fm.all("KindCode"+strFlag)[index])&&isEmpty(fm.all("ItemKind"+strFlag+"_Context")[index]))
  {
    strQueryString = "RiskCode="+fm.RiskCode.value
                   + "&ClauseType=SubClause"
                   + "&ClauseCode="+fm.all("KindCode"+strFlag)[index].value
                   + "&Language="+fm.Language.value
                   + "&ClauseFlag=3";
    fm.all("ItemKind"+strFlag+"_Context")[index].value = getClauseContext(strQueryString);
  }
  fm.Currency1Fee.style.display = "none"; //打开扩展显示(按钮...)的时候，将币别暂时置为不可见 2009-04-18
  showSubPage(field,strSpanName);
}

//打开扩展显示(按钮...)的时候会将覆盖到的select标签显示置为none，关闭时将其恢复 2009-04-18 begin
function showSelectFieldZK(field, strFlag) {
	if (strFlag == "Currency1Fee"){
	  fm.Currency1Fee.style.display = "";
	} 
	else if(strFlag == "CoinsFlag"){
	  fm.CoinsFlag.style.display = "";	
	}
}
//打开扩展显示(按钮...)的时候会将覆盖到的select标签显示置为none，关闭时将其恢复 2009-04-18 end

function checkAddressNo(field)
{
  var arrayAddressNo = Array();
  var i = 0;
  
  try
  {
    arrayAddressNo = getAddressNoFromAddress();
    for(i=0;i<arrayAddressNo.length;i++)
    {
      if(trim(field.value)==arrayAddressNo[i])	
        return true;    
    }
  }
  catch(ex)
  {
  }

  errorMessage("无此地址序号,请先录入地址信息！");
  field.focus();
  field.select();
  return false;
}
function checkAddressNoUpdate(field)
{
  var i = 0;
  
  try
  {
    for(i=1;i<=getRowsCount("Address");i++)
    {
       if(trim(field.value)==fm.AddressNo[i].value){
       
    	  if(fm.Address_Flag[i].value!="D"){
           return true;
        }
      }
    }
  }
  catch(ex)
  {
  }
  field.value="";
  errorMessage("无此地址序号,请先录入地址信息！");
  field.focus();
  field.select();
  return false;
}

function getAddressNoFromItemKind()
{
  var arrayAddressNo = new Array();
  var intRowsCount = 0;
  var i = 0;

  //主险
  for(i=1;i<=getRowsCount("ItemKindMain");i++)
  {
    arrayAddressNo[i-1] = fm.AddressNoMain[i].value;
  }
  intRowsCount = intRowsCount+i;
  //利润损失附加险
  try
  {
    for(i=1;i<=getRowsCount("ItemKindLoss");i++)
    {
      arrayAddressNo[i+intRowsCount-1] = fm.AddressNoLoss[i].value;
    }
    intRowsCount = intRowsCount+i;
  }
  catch(ex)
  {
  }

  return arrayAddressNo;
}

function setAddressNoToItemKind(obj)
{
  var intRowsCount = 0;
  var i = 0;

  //主险
  intRowsCount = getRowsCount("ItemKindMain");
  for(i=0;i<intRowsCount&&i<obj.length;i++)
  {
    fm.AddressNoMain[i+1].value = obj[i];
  }
  //利润损失附加险
  try
  {
    intRowsCount = intRowsCount+getRowsCount("ItemKindLoss");
    for(i=0;i<intRowsCount&&i<obj.length;i++)
    {
      fm.AddressNoLoss[i+1].value = obj[i];
    }
  }
  catch(ex)
  {
  }
}

function getCollectItemKindFee()
{
  var arrayItemKindFee = new Array();
  var strRiskCode = fm.RiskCode.value;
  //主险
  arrayItemKindFee = arrayItemKindFee.concat(getItemKindMain());
  //附加险/附加条款
  try
  {
    arrayItemKindFee = arrayItemKindFee.concat(getItemKindSub());
  }
  catch(ex)
  {
  }
  //第一部分 附加险 责任
   try
  {
    arrayItemKindFee = arrayItemKindFee.concat(getItemKindLossMainSub());
  }
  catch(ex)
  {
  }
//人身伤害险
	try {
		
		arrayItemKindFee = arrayItemKindFee.concat(getItemKindHurtMain());
		
	} catch (ex) {
	}
	//人身伤害险
	try {
		
		arrayItemKindFee = arrayItemKindFee.concat(getItemKindHurtSub());
		
	} catch (ex) {
	}
  //利润损失附加险
  try
  {
    arrayItemKindFee = arrayItemKindFee.concat(getItemKindLoss());
  }
  catch(ex)
  {
  }
  //利润损失附加险附加条款
  try
  {
    arrayItemKindFee = arrayItemKindFee.concat(getItemKindLossSub());
  }
  catch(ex)
  {
  }

  //以币别为纬度得到汇总数组：币别代码、币别名称、是否计入保额、保额、保费
  arrayItemKindFee = collectByCurrencyAndCalculateFlag(arrayItemKindFee); //该函数在UICommon.js中
  return arrayItemKindFee;
}
function getCollectItemKindFee6603() {
	var arrayItemKindFee = new Array();
	var strRiskCode = fm.RiskCode.value;
	// 主险
	arrayItemKindFee = arrayItemKindFee.concat(getItemKindMain6603());
	// 附加险/附加条款
	try {
		arrayItemKindFee = arrayItemKindFee.concat(getItemKindSub());
	} catch (ex) {
	}
	//人身伤害险
	try {
		
		arrayItemKindFee = arrayItemKindFee.concat(getItemKindHurtMain());
		
	} catch (ex) {
	}
	// 营业中断附加险
	try {
		arrayItemKindFee = arrayItemKindFee.concat(getItemKindLoss6603());
	} catch (ex) {
	}
	// 营业中断附加险附加条款
	try {
		arrayItemKindFee = arrayItemKindFee.concat(getItemKindLossSub());
	} catch (ex) {
	}

	// 以币别为纬度得到汇总数组：币别代码、币别名称、是否计入保额、保额、保费
	arrayItemKindFee = collectByCurrencyAndCalculateFlag(arrayItemKindFee); // 该函数在UICommon.js中
	return arrayItemKindFee;
}

function getCollectOldItemKindFee()
{
  var arrayItemKindFee = new Array();

  //主险
  arrayItemKindFee = arrayItemKindFee.concat(getOldItemKindMain());
  //附加险/附加条款
  try
  {
    arrayItemKindFee = arrayItemKindFee.concat(getOldItemKindSub());
  }
  catch(ex)
  {
  }
  //人身伤害险
  try
  {
    arrayItemKindFee = arrayItemKindFee.concat(getOldItemKindHurtMain());
  }
  catch(ex)
  {
  }
  //利润损失附加险
  try
  {
    arrayItemKindFee = arrayItemKindFee.concat(getOldItemKindLoss());
  }
  catch(ex)
  {
  }
  //利润损失附加险附加条款
  try
  {
    arrayItemKindFee = arrayItemKindFee.concat(getOldItemKindLossSub());
  }
  catch(ex)
  {
  }
 

  //以币别为纬度得到汇总数组：币别代码、币别名称、是否计入保额、保额、保费
  arrayItemKindFee = collectByCurrencyAndCalculateFlag(arrayItemKindFee); //该函数在UICommon.js中
  return arrayItemKindFee;
}

function calShortRate(index,strFlag)
{
  //var dbDiscountOld = parseFloat(fm.all("Discount"+strFlag)[index].title);
  //var dbDiscountNew = parseFloat(fm.all("Discount"+strFlag)[index].value);
  var dbAmountOld = parseFloat(fm.all("Amount"+strFlag)[index].title);
  var dbAmountNew = parseFloat(fm.all("Amount"+strFlag)[index].value);
  var dbRateOld = parseFloat(fm.all("Rate"+strFlag)[index].title);
  var dbRateNew = parseFloat(fm.all("Rate"+strFlag)[index].value);

  if(isNaN(dbAmountOld))
    dbAmountOld = 0;
  if(isNaN(dbAmountNew))
    dbAmountNew = 0;
  if(isNaN(dbRateOld))
    dbRateOld = 0;
  if(isNaN(dbRateNew))
    dbRateNew = 0;

  //不计
  if(fm.all("ShortRateFlag"+strFlag)[index].value=="3")
  {
    return 100.0000;
  }
  //减保
  else if(fm.all("ItemKind"+strFlag+"_Flag")[index].value=="D"||
          dbAmountOld>dbAmountNew||
          dbRateOld>dbRateNew)
  {
    //新短期费率参与退费计算，所以退费要少，短期费率要小
    //未了责任短期费率=原短期费率-已了责任月份数（或天数）对应的短期费率
    return getShortRate(fm.all("ShortRateFlag"+strFlag)[index].value,
                        fm.all("StartDate"+strFlag)[index].title,
                        fm.StartHour.title,
                        fm.all("EndDate"+strFlag)[index].title,
                        fm.EndHour.title,fm.all("KindCode" + strFlag)[index].value)-
           getShortRate(fm.all("ShortRateFlag"+strFlag)[index].value,
                        fm.all("StartDate"+strFlag)[index].value,
                        fm.StartHour.value,
                        getNextDateFullDate(fm.ValidDate.value,-1),
                        fm.EndHour.value,fm.all("KindCode" + strFlag)[index].value);
  }
  //加保
  else
  {
    //新短期费率参与加费计算，所以加费要多，短期费率要大
    //未了责任短期费率=未了责任月份数（或天数）对应的短期费率
    return getShortRate(fm.all("ShortRateFlag"+strFlag)[index].value,
                        fm.ValidDate.value,
                        fm.ValidHour.value,
                        fm.EndDate.value,
                        fm.EndHour.value,fm.all("KindCode" + strFlag)[index].value);
  }
}

function formulizePremium(index,strFlag)
{ 
  var dbNewPremium = 0;
  var dbChgPremium = 0;
  
  var uwType="E1";
  var strRiskCode = fm.RiskCode.value;
  
  var dbOldShortRate = parseFloat(fm.all("ShortRate"+strFlag)[index].title); //原短期费率系数
  var dbOldDiscount = parseFloat(fm.all("Discount"+strFlag)[index].title); //原折扣
  var dbOldAmount = parseFloat(fm.all("Amount"+strFlag)[index].title); //原保额
  var dbOldRate = parseFloat(fm.all("Rate"+strFlag)[index].title); //原年费率
  var dbOldPremium = parseFloat(fm.all("Premium"+strFlag)[index].title); //原保费
  var dbOldWageMonths = parseFloat(fm.WageMonths.title); //原保费
  var dbNewShortRate = parseFloat(fm.all("ShortRate"+strFlag)[index].value); //短期费率系数
  var dbNewDiscount = parseFloat(fm.all("Discount"+strFlag)[index].value); //折扣
  var dbNewAmount = parseFloat(fm.all("Amount"+strFlag)[index].value); //保额
  var dbNewRate = parseFloat(fm.all("Rate"+strFlag)[index].value); //年费率
  var dbWageMonths = parseFloat(fm.WageMonths.value); // 最大赔偿期/月 
  var  dboldTurnover=parseFloat(fm.all("Value" + strFlag)[index].title); //
  var  dbnewTurnover=parseFloat(fm.all("Value" + strFlag)[index].value); //
  /*if("Loss"==strFlag){
	  //dbOldAmount = dboldTurnover;
	  //dbNewAmount = dbnewTurnover;
	  if(fm.BusinessSource1.value=='X3'){
		  dbOldAmount=parseFloat(500000);
		  dbNewAmount=parseFloat(500000); 
		}else if(fm.BusinessSource1.value=='X6'){
			dbOldAmount=parseFloat(800000); 
			dbNewAmount=parseFloat(800000);
		}else if(fm.BusinessSource1.value=='X7'){
			dbOldAmount=parseFloat(600000); 
			dbNewAmount=parseFloat(600000);
		}else{
			//dbOldAmount = dboldTurnover;
			//dbNewAmount = dbnewTurnover;
		}
  }*/
/*  if("LossSub"==strFlag){
	  //dbOldAmount = dboldTurnover;
	  //dbNewAmount = dbnewTurnover;
	  var intIndex2= document.getElementsByName("button_ItemKindLossSub_Delete").length-1;
		if(intIndex2>0){
		  }
  }*/
  if(isNaN(dbOldShortRate))
    dbOldShortRate = 0;
  if(isNaN(dbOldDiscount))
    dbOldDisCount = 0;
  if(isNaN(dbOldAmount))
    dbOldAmount = 0;
  if(isNaN(dbOldRate))
    dbOldRate = 0;
  if(isNaN(dbOldPremium))
	    dbOldPremium = 0;
  if(isNaN(dbOldWageMonths))
	  dbOldWageMonths = 0;

  if(isNaN(dbNewShortRate))
    dbNewShortRate = 0;
  if(isNaN(dbNewDiscount))
    dbNewDisCount = 0;
  if(isNaN(dbNewAmount))
    dbNewAmount = 0;
  if(isNaN(dbNewRate))
    dbNewRate = 0;
  if(isNaN(dbWageMonths))
	dbWageMonths = 0;
//组织保费的计算公式元素
	var jsonObj={
			"riskCode":strRiskCode,
			"uwType":uwType,
			"dbOldAmount":dbOldAmount,
			"dbOldRate":dbOldRate,
			"dbOldShortRate":dbOldShortRate,
			"dbOldDiscount":dbOldDiscount,
			"dbOldPremium":dbOldPremium,
			"dbNewAmount":dbNewAmount,
			"dbNewRate":dbNewRate,
			"dbNewShortRate":dbNewShortRate,
			"dbNewDiscount":dbNewDiscount
		}
  //xiaojian_leave：页面上应该隐藏费率因子，该因子对应PrpDrisk.Calculator，在初始化文件中赋值
  //if(dbNewAmount*dbNewRate/1000*dbNewDiscount/100==
  //   dbOldAmount*dbOldRate/1000*dbOldDiscount/100)
  /*if(dbNewAmount*dbNewRate/1000==
     dbOldAmount*dbOldRate/1000)
  {
    //dbNewPremium = dbNewAmount*dbNewRate/1000*dbNewDiscount/100*dbNewShortRate/100;
    dbNewPremium = dbNewAmount*dbNewRate/1000* dbNewShortRate/100;
  }*/
  /*else
  {
    dbChgPremium += calculateByItem(dbOldAmount,
                                    dbNewAmount,
                                    dbOldRate/1000,
                                    dbNewRate/1000,
                                    1, //dbOldDiscount/100,
                                    1, //dbNewDiscount/100,
                                    dbNewShortRate/100);
    dbNewPremium = dbOldPremium+dbChgPremium;   
  }*/
	//获取险别的值
	if(typeof(fm.all("KindCode" + strFlag)[index])!="undefined"&&fm.all("KindCode" + strFlag)[index]!=undefined){
		var kindCode=fm.all("KindCode" + strFlag)[index].value;
		jsonObj["kindCode"]=kindCode;
	}
	var jsonStr="";
	for(var str in jsonObj){
		jsonStr+=str+"="+jsonObj[str]+"&";
	}
	jsonStr=jsonStr.substring(0, jsonStr.lastIndexOf("&"));
	var json=ajaxGetPremium(jsonStr);
	//fm.all("Amount" + strFlag)[index].value=parseFloat(json.dbNewAmount).toFixed(2);
	dbNewPremium=json.Premiumkind;
  if(dbNewPremium<0)
    dbNewPremium = 0;

  return dbNewPremium; //格式化的处理应该在最后一层中
}
function formulizePremium6603(index,strFlag)
{ 
  var dbNewPremium = 0;
  var dbChgPremium = 0;
  
  var dbOldAddFeeRate = parseFloat(fm.all("AjustRateMain")[index].title); //加费比例;
  var dbNewAddFeeRate = parseFloat(fm.all("AjustRateMain")[index].value); //加费比例;
  //alert(dbOldAddFeeRate+" "+dbOldAddFeeRate);

  var dbOldShortRate = parseFloat(fm.all("ShortRate"+strFlag)[index].title); //原短期费率系数
  //var dbOldDiscount = parseFloat(fm.all("Discount"+strFlag)[index].title); //原折扣
  var dbOldAmount = parseFloat(fm.all("Amount"+strFlag)[index].title); //原保额
  var dbOldRate = parseFloat(fm.all("Rate"+strFlag)[index].title); //原年费率
  var dbOldPremium = parseFloat(fm.all("Premium"+strFlag)[index].title); //原保费

  var dbOldWageMonths = parseFloat(fm.WageMonths.title); //原保费


  var dbNewShortRate = parseFloat(fm.all("ShortRate"+strFlag)[index].value); //短期费率系数
  //var dbNewDiscount = parseFloat(fm.all("Discount"+strFlag)[index].value); //折扣
  var dbNewAmount = parseFloat(fm.all("Amount"+strFlag)[index].value); //保额
  var dbNewRate = parseFloat(fm.all("Rate"+strFlag)[index].value); //年费率
  var dbWageMonths = parseFloat(fm.WageMonths.value); // 最大赔偿期/月

  if(isNaN(dbOldShortRate))
    dbOldShortRate = 0;
  //if(isNaN(dbOldDisCount))
  //  dbOldDisCount = 0;
  if(isNaN(dbOldAmount))
    dbOldAmount = 0;
  if(isNaN(dbOldRate))
    dbOldRate = 0;
  if(isNaN(dbOldPremium))
	    dbOldPremium = 0;
  if(isNaN(dbOldWageMonths))
	  dbOldWageMonths = 0;

  if(isNaN(dbNewShortRate))
    dbNewShortRate = 0;
  //if(isNaN(dbNewDisCount))
  //  dbNewDisCount = 0;
  if(isNaN(dbNewAmount))
    dbNewAmount = 0;
  if(isNaN(dbNewRate))
    dbNewRate = 0;
  if(isNaN(dbWageMonths))
	dbWageMonths = 0;

  //xiaojian_leave：页面上应该隐藏费率因子，该因子对应PrpDrisk.Calculator，在初始化文件中赋值
  //if(dbNewAmount*dbNewRate/1000*dbNewDiscount/100==
  //   dbOldAmount*dbOldRate/1000*dbOldDiscount/100)
  dbNewAmount = dbNewAmount*dbNewAddFeeRate/100;
  dbOldAmount = dbOldAmount*dbOldAddFeeRate/100;
  if(dbNewAmount*dbNewRate/1000==
     dbOldAmount*dbOldRate/1000)
  {
    //dbNewPremium = dbNewAmount*dbNewRate/1000*dbNewDiscount/100*dbNewShortRate/100;
    dbNewPremium = dbNewAmount*dbNewRate/1000* dbNewShortRate/100;
  }
  else
  {
	  
    dbChgPremium += calculateByItem(dbOldAmount,
                                    dbNewAmount,
                                    dbOldRate/1000,
                                    dbNewRate/1000,
                                    1, //dbOldDiscount/100,
                                    1, //dbNewDiscount/100,
                                    dbNewShortRate/100);
    dbNewPremium = dbOldPremium+dbChgPremium;
  }
  if(dbNewPremium<0)
    dbNewPremium = 0;

  return dbNewPremium; //格式化的处理应该在最后一层中
}

function calAllPremium()
{
  var i = 0;
  //主险
  for(i=1;i<=getRowsCount("ItemKindMain");i++)
  {
    fm.StartDateMain[i].value = fm.StartDate.value;
    fm.EndDateMain[i].value = fm.EndDate.value;
    calculatePremiumMain(fm.ShortRateMain[i],1);
  }
  //附加险/附加条款
  try
  {
    for(i=1;i<=getRowsCount("ItemKindSub");i++)
    {
      fm.StartDateSub[i].value = fm.StartDate.value;
      fm.EndDateSub[i].value = fm.EndDate.value;
      calculatePremiumSub(fm.ShortRateSub[i],1);
    }
  }
  catch(ex)
  {
  }
  //第一部分 附加责任保险
  try
  {
    for(i=1;i<=getRowsCount("ItemKindLossMainSub");i++)
    {
      fm.StartDateSub[i].value = fm.StartDate.value;
      fm.EndDateSub[i].value = fm.EndDate.value;
      calculatePremiumLossMainSub(fm.ShortRateLossMainSub[i],1);
    }
  }
  catch(ex)
  {
  }
  //人身伤害险
  try
  {
    for(i=1;i<=getRowsCount("ItemKindHurtMain");i++)
    {
      fm.StartDateHurtMain[i].value = fm.StartDate.value;
      fm.EndDateHurtMain[i].value = fm.EndDate.value;
      calculatePremiumHurtMain(fm.ShortRateHurtMain[i],1);
    }
  }
  catch(ex)
  {
  }
  //人身伤害险 附加险
  try
  {
    for(i=1;i<=getRowsCount("ItemKindHurtSub");i++)
    {
      fm.StartDateHurtSub[i].value = fm.StartDate.value;
      fm.EndDateHurtSub[i].value = fm.EndDate.value;
      calculatePremiumHurtSub(fm.ShortRateHurtSub[i],1);
    }
  }
  catch(ex)
  {
  }
  //利润损失附加险
  try
  {
    for(i=1;i<=getRowsCount("ItemKindLoss");i++)
    {
      fm.StartDateLoss[i].value = fm.StartDate.value;
      fm.EndDateLoss[i].value = fm.EndDate.value;
      calculatePremiumLoss(fm.ShortRateLoss[i],1);
    }
  }
  catch(ex)
  {
  }
   //第一部分 附加 责任附加险
  try
  {
    for(i=1;i<=getRowsCount("ItemKindLossMainSub");i++)
    {
      fm.StartDateLossMainSub[i].value = fm.StartDate.value;
      fm.EndDateLossMainSub[i].value = fm.EndDate.value;
      calculatePremiumLossMainSub(fm.ShortRateLoss[i],1);
    }
  }
  catch(ex)
  {
  }
  //利润损失附加险附加条款
  try
  {
    for(i=1;i<=getRowsCount("ItemKindLossSub");i++)
    {
      fm.StartDateLossSub[i].value = fm.StartDate.value;
      fm.EndDateLossSub[i].value = fm.EndDate.value;
      calculatePremiumLossSub(fm.ShortRateLossSub[i],1);
    }
  }
  catch(ex)
  {
  }

  setRefreshFlagFeeZero();
}

function setSumAmountPremiumSpecialToItemKind()
{
  //物质损失保险汇总
  fm.SumAmountMainSub.value = pointTwo(parseFloat(fm.SumAmountMain.value)+parseFloat(fm.SumAmountSub.value));
  fm.CurrencySumAmountMainSub.value = fm.Currency2Fee.value;
  fm.CurrencyNameSumAmountMainSub.value = fm.CurrencyName2Fee.value;
  fm.SumPremiumMainSub.value = pointTwo(parseFloat(fm.SumPremiumMain.value)+parseFloat(fm.SumPremiumSub.value));
  fm.CurrencySumPremiumMainSub.value = fm.Currency2Fee.value;
  fm.CurrencyNameSumPremiumMainSub.value = fm.CurrencyName2Fee.value;
  //利润损失保险汇总
  fm.SumAmountLossLossSub.value = pointTwo(parseFloat(fm.SumAmountLoss.value)+parseFloat(fm.SumAmountLossSub.value));
  fm.CurrencySumAmountLossLossSub.value = fm.Currency2Fee.value;
  fm.CurrencyNameSumAmountLossLossSub.value = fm.CurrencyName2Fee.value;
  fm.SumPremiumLossLossSub.value = pointTwo(parseFloat(fm.SumPremiumLoss.value)+parseFloat(fm.SumPremiumLossSub.value));
  fm.CurrencySumPremiumLossLossSub.value = fm.Currency2Fee.value;
  fm.CurrencyNameSumPremiumLossLossSub.value = fm.CurrencyName2Fee.value;
}

//modify by wuxiaodonng 051117 reasion 删除免赔同时删除特约中有关免赔的信息
function deleteDeductibleTextEngage(strFlag)
{
  var strClauseCode = "";

  if(strFlag=="Sub")
    strClauseCode = "TX001";
  else if(strFlag=="Loss")
    strClauseCode = "TX002";
  else if(strFlag=="Main")
    strClauseCode = "TX001";

  for(var i=1;i<=getRowsCount("Engage");i++)
  {
    if(fm.ClauseCode[i].value==strClauseCode)
    {
      deleteEngage(fm.button_Engage_Delete[i],1,1);
      break;
    }
  }
}
function setItemKindAddressNo() {
	for (i = 1; i < fm.all("AddressCode").length; i++) {
		if (fm.AddressCode[i].value != "" && fm.AddressName[i].value != "") {
			if(fm.all("AddressNoMain") != null){
			  var k = fm.all("AddressNoMain").length;
			  fm.AddressNoMain[k - 1].value = fm.AddressNoMain[i].value;
			}
			break;
		}
	}
}

function setItemKindAddressNoLoss() {
	for (i = 1; i < fm.all("AddressCode").length; i++) {
		if (fm.AddressCode[i].value != "" && fm.AddressName[i].value != "") {
			if(fm.all("AddressNoLoss") != null){
			  var k = fm.all("AddressNoLoss").length;
			  fm.AddressNoLoss[k - 1].value = fm.AddressNo[i].value;
			}
			break;
		}
	}
}
function setItemKindAddressNoLossMainSub() {
	for (i = 1; i < fm.all("AddressCode").length; i++) {
		if (fm.AddressCode[i].value != "" && fm.AddressName[i].value != "") {
			if(fm.all("AddressNoLossMainSub") != null){
			  var k = fm.all("AddressNoLossMainSub").length;
			  fm.AddressNoLossMainSub[k - 1].value = fm.AddressNo[i].value;
			}
			break;
		}
	}
}
function CheckThisSubRiskAmount(){                  //检测指定的附加险的保额 不能为空
	var checkThisSubRiskAmountRisk = "NoCheck";
    
	try{
		checkThisSubRiskAmountRisk = fm.CheckThisSubRiskAmount.value;
	}catch(ex){
		checkThisSubRiskAmountRisk = "NoCheck";
	}
	
	if(checkThisSubRiskAmountRisk == "NoCheck"){
		return true;
	}

	var intRowsSubCount = getRowsCount("ItemKindSub");
	for (var i = 1; i <= intRowsSubCount; i++){		
		if(checkThisSubRiskAmountRisk.indexOf('#'+fm.KindCodeSub[i].value+'#') >= 0){
			if (isEmpty(fm.AmountSub[i]) || parseFloat(fm.AmountSub[i].value) <= 0){
				errorMessage(fm.KindNameSub[i].value + "的"+ fm.AmountSub[i].description + "不能为空或数值小于等于零！");
				fm.AmountSub[i].focus();
				return false;
			}
		}
	}
	
	try {
		var intRowsLossSubCount = getRowsCount("ItemKindLossSub");
		for (var i = 1; i <= intRowsLossSubCount; i++){		
			if(checkThisSubRiskAmountRisk.indexOf('#'+fm.KindCodeLossSub[i].value+'#') >= 0){
				if (isEmpty(fm.AmountLossSub[i]) || parseFloat(fm.AmountLossSub[i].value) <= 0){
					errorMessage(fm.KindNameLossSub[i].value + "的"+ fm.AmountLossSub[i].description + "不能为空或数值小于等于零！");
					fm.AmountLossSub[i].focus();
					return false;
				}
			}
		}
	} catch (ex) {
	}
	
	return true;
}

function showItemKindDetail(field, strFlag) {
	var strQueryString = "";
	var strSpanName = "span_ItemKind" + strFlag + "_Context";
	fm.Currency1Fee.style.display = "none"; //打开扩展显示(按钮...)的时候，将币别暂时置为不可见 2009-04-18
	showSubPage(field, strSpanName);
}

function setItemKindSubDetailEngageFlagPG()
{	
  var index = 0;
  for(index=1;index<=getRowsCount("ItemKindSub");index++)
  {
	fm.ItemKindSubDetailEngage_Flag[index].value = "";
    if(fm.ItemKindSub_Flag[index].value!="U")
    {
      fm.ItemKindSubDetailEngage_Flag[index].value = fm.ItemKindSub_Flag[index].value;
    }
    else
    {
     
	     // if(fm.ItemKindSubDetail_Context[index].value!=fm.ItemKindSubDetail_Context[index].title)
	      //{
	      //  //fm.ItemKindSubDetailEngage_Flag[index].value = "U";
	      //}
	      if(fm.DeductibleRateSub[index].value!=fm.DeductibleRateSub[index].title||
	         fm.ShortRateFlagSub[index].value!=fm.ShortRateFlagSub[index].title||
	         fm.ShortRateSub[index].value!=fm.ShortRateSub[index].title||
	         fm.KindCodeSub[index].value!=fm.KindCodeSub[index].title||
	         fm.KindNameSub[index].value!=fm.KindNameSub[index].title||
	         //fm.ItemNameSub[index].value!=fm.ItemNameSub[index].title||
	         //fm.ItemDetailNameSub[index].value!=fm.ItemDetailNameSub[index].title||
	         fm.CurrencySub[index].value!=fm.CurrencySub[index].title||
	         fm.AmountSub[index].value!=fm.AmountSub[index].title||
	         fm.RateSub[index].value!=fm.RateSub[index].title||
	         fm.PremiumSub[index].value!=fm.PremiumSub[index].title)
	      {
	        fm.ItemKindSub_Flag[index].value = "U";
	      }
	      else
	      {
	    	  if(fm.ItemKindSub_Flag[index].value != "U") {
	    		  fm.ItemKindSub_Flag[index].value = "";
	    	  }
	      }
    }
  }
}

function setItemKindLossSubDetailEngage_FlagPG()
{
  var index = 0;
  for(index=1;index<=getRowsCount("ItemKindLossSub");index++)
  {
    fm.ItemKindLossSubDetailEngage_Flag[index].value = "";
    if(fm.ItemKindLossSub_Flag[index].value!="U")
    {
      fm.ItemKindLossSubDetailEngage_Flag[index].value = fm.ItemKindLossSub_Flag[index].value;
    }
    else
    {
      //if(fm.ItemKindLossSubDetail_Context[index].value!=fm.ItemKindLossSubDetail_Context[index].title)
      //{
        //fm.ItemKindLossSubDetailEngage_Flag[index].value = "U";
     // }
      if(fm.DeductibleRateLossSub[index].value!=fm.DeductibleRateLossSub[index].title||
         
         fm.ShortRateFlagLossSub[index].value!=fm.ShortRateFlagLossSub[index].title||
         fm.ShortRateLossSub[index].value!=fm.ShortRateLossSub[index].title||
         fm.KindCodeLossSub[index].value!=fm.KindCodeLossSub[index].title||
         fm.KindNameLossSub[index].value!=fm.KindNameLossSub[index].title||
         //fm.ItemNameLossSub[index].value!=fm.ItemNameLossSub[index].title||
         //fm.ItemDetailNameLossSub[index].value!=fm.ItemDetailNameLossSub[index].title||
         fm.CurrencyLossSub[index].value!=fm.CurrencyLossSub[index].title||
         fm.AmountLossSub[index].value!=fm.AmountLossSub[index].title||
         fm.RateLossSub[index].value!=fm.RateLossSub[index].title||
         fm.PremiumLossSub[index].value!=fm.PremiumLossSub[index].title)
      {
        fm.ItemKindLossSub_Flag[index].value = "U";
      }
      else
      {
        //fm.ItemKindLossSub_Flag[index].value = "";
      }
    }
  }
}
//主险，营业中断险免赔条件更改
function FreeO(selval) {
	if(selval.isline == "yyzd"){
		var yyzdFree = document.getElementById("yyzdFree");
		yyzdFree.value = selval.value;
	}else if(selval.isline == "zx"){
		var FreeInput = document.getElementById("FreeInput");
		FreeInput.value = selval.value;
	}
}
//营业中断
function getWageMonths2(){

	var dbWageHeadWeeks0 = parseFloat(fm.WageHeadWeeks0.value); // 约定的维持费用-工资
	var dbWageMonths = parseFloat(fm.WageMonths.value); // 最大赔偿期/月

	if (isNaN(dbWageMonths))
		dbWageMonths = 0;
	if (isNaN(dbWageHeadWeeks0))
		dbWageHeadWeeks0 = 0;
	
	fm.WageMonths.value = dbWageHeadWeeks0;
}




//人身伤害险


function insertItemKindHurtMain()
{
  var intRowsCount = getRowsCount("ItemKindHurtMain");

  insertRowForPG('ItemKindHurtMain','ItemKindHurtMain_Data');
  
  setcloneNodeEventOfTablePG("ItemKindHurtMain");
  
  fm.StartDateHurtMain[intRowsCount+1].value = fm.ValidDate.value;
  fm.EndDateHurtMain[intRowsCount+1].value = fm.EndDate.value;
  resetItemKindNo(); //该函数在框架的js中
  setItemKindAddressNo();// 若被保险财产座落地址不为空将在主险中自动带出序号
  calculatePremiumHurtMain(fm.ShortRateFlagHurtMain[intRowsCount + 1],1);//计算短期费率
}
function insertItemKindHurtSub()
{
  var intRowsCount = getRowsCount("ItemKindHurtSub");

  insertRowForPG('ItemKindHurtSub','ItemKindHurtSub_Data');
  
  setcloneNodeEventOfTablePG("ItemKindHurtSub");
  
  fm.StartDateHurtSub[intRowsCount+1].value = fm.ValidDate.value;
  fm.EndDateHurtSub[intRowsCount+1].value = fm.EndDate.value;
  resetItemKindNo(); //该函数在框架的js中
  setItemKindAddressNo();// 若被保险财产座落地址不为空将在主险中自动带出序号
  calculatePremiumHurtSub(fm.ShortRateFlagHurtSub[intRowsCount + 1],1);//计算短期费率
}

function getItemKindHurtMain() {
	
	arrayItemKindHurtMainRow = new Array();
	var arrayItemKindHurtMain = new Array();
	var i = 0;
    
	for (i = 1; i <= getRowsCount("ItemKindHurtMain"); i++) {
		
		arrayItemKindHurtMainRow = new Array();

		arrayItemKindHurtMainRow.KindCode = fm.KindCodeHurtMain[i].value;
		
		
		
		// xiaojian_leave：在页面上增加是否算入总保额的隐藏字段，在初始化文件中赋值：PrpDkind.CalculateFlag[1]
		arrayItemKindHurtMainRow.CalculateFlag = fm.CalculateFlagHurtMain[i].value;
		//arrayItemKindHurtMainRow.CalculateFlag = "N";
		
		arrayItemKindHurtMainRow.ItemCode = fm.ItemCodeHurtMain[i].value;
		
		arrayItemKindHurtMainRow.Currency = fm.CurrencyHurtMain[i].value;
		
		arrayItemKindHurtMainRow.CurrencyName = fm.CurrencyNameHurtMain[i].value;
		
		arrayItemKindHurtMainRow.ExchangeRate = fm.ExchangeRateHurtMain[i].value;
		
		arrayItemKindHurtMainRow.Amount = parseFloat(fm.AmountHurtMain[i].value);
		
		arrayItemKindHurtMainRow.Rate = parseFloat(fm.RateHurtMain[i].value);
		
		arrayItemKindHurtMainRow.Discount = parseFloat(fm.DiscountHurtMain[i].value);
		
		arrayItemKindHurtMainRow.Premium = parseFloat(fm.PremiumHurtMain[i].value);
		
		if (isNaN(arrayItemKindHurtMainRow.ExchangeRate))
			arrayItemKindHurtMainRow.ExchangeRate = 0;
		if (isNaN(arrayItemKindHurtMainRow.Amount))
			arrayItemKindHurtMainRow.Amount = 0;
		if (isNaN(arrayItemKindHurtMainRow.Rate))
			arrayItemKindHurtMainRow.Rate = 0;
		if (isNaN(arrayItemKindHurtMainRow.Discount))
			arrayItemKindHurtMainRow.Discount = 0;
		if (isNaN(arrayItemKindHurtMainRow.Premium))
			arrayItemKindHurtMainRow.Premium = 0;
		
		arrayItemKindHurtMain[arrayItemKindHurtMain.length] = arrayItemKindHurtMainRow; // 一个标的信息
		
		 
		 
	}
	
	return arrayItemKindHurtMain;
}
function getItemKindHurtSub() {
	
	arrayItemKindHurtSubRow = new Array();
	var arrayItemKindHurtSub = new Array();
	var i = 0;
    
	for (i = 1; i <= getRowsCount("ItemKindHurtSub"); i++) {
		
		arrayItemKindHurtSubRow = new Array();

		arrayItemKindHurtSubRow.KindCode = fm.KindCodeHurtSub[i].value;
		
		
		
		// xiaojian_leave：在页面上增加是否算入总保额的隐藏字段，在初始化文件中赋值：PrpDkind.CalculateFlag[1]
		arrayItemKindHurtSubRow.CalculateFlag = fm.CalculateFlagHurtSub[i].value;
		//arrayItemKindHurtSubRow.CalculateFlag = "N";
		
		arrayItemKindHurtSubRow.ItemCode = fm.ItemCodeHurtSub[i].value;
		
		arrayItemKindHurtSubRow.Currency = fm.CurrencyHurtSub[i].value;
		
		arrayItemKindHurtSubRow.CurrencyName = fm.CurrencyNameHurtSub[i].value;
		
		arrayItemKindHurtSubRow.ExchangeRate = fm.ExchangeRateHurtSub[i].value;
		
		arrayItemKindHurtSubRow.Amount = parseFloat(fm.AmountHurtSub[i].value);
		
		arrayItemKindHurtSubRow.Rate = parseFloat(fm.RateHurtSub[i].value);
		
		arrayItemKindHurtSubRow.Discount = parseFloat(fm.DiscountHurtSub[i].value);
		
		arrayItemKindHurtSubRow.Premium = parseFloat(fm.PremiumHurtSub[i].value);
		
		if (isNaN(arrayItemKindHurtSubRow.ExchangeRate))
			arrayItemKindHurtSubRow.ExchangeRate = 0;
		if (isNaN(arrayItemKindHurtSubRow.Amount))
			arrayItemKindHurtSubRow.Amount = 0;
		if (isNaN(arrayItemKindHurtSubRow.Rate))
			arrayItemKindHurtSubRow.Rate = 0;
		if (isNaN(arrayItemKindHurtSubRow.Discount))
			arrayItemKindHurtSubRow.Discount = 0;
		if (isNaN(arrayItemKindHurtSubRow.Premium))
			arrayItemKindHurtSubRow.Premium = 0;
		
		arrayItemKindHurtSub[arrayItemKindHurtSub.length] = arrayItemKindHurtSubRow; // 一个标的信息
		
		 
		 
	}
	
	return arrayItemKindHurtSub;
}




function getCollectItemKindHurtMain() {
	var arrayItemKindHurtMain = new Array();
	return arrayItemKindHurtMain;
}
function getCollectItemKindHurtSub() {
	var arrayItemKindHurtSub = new Array();
	return arrayItemKindHurtSub;
}

function calculatePremiumHurtMain(field, strCalculateShortRateFlag) {
	var index = getElementOrder(field) - 1;
	//if (parseInt(strCalculateShortRateFlag, 10) == 1)
		fm.all("ShortRateHurtMain")[index].value = pointFour(round(calShortRate(
				index, "HurtMain"), 4));
	fm.all("PremiumHurtMain")[index].value = pointTwo(round(formulizePremium(index,
			"HurtMain"), 2));
	
	setRefreshFlagFeeZero();
}
function calculatePremiumHurtSub(field, strCalculateShortRateFlag) {
	var index = getElementOrder(field) - 1;
	//if (parseInt(strCalculateShortRateFlag, 10) == 1)
		fm.all("ShortRateHurtSub")[index].value = pointFour(round(calShortRate(
				index, "HurtSub"), 4));
	fm.all("PremiumHurtSub")[index].value = pointTwo(round(formulizePremium(index,
			"HurtSub"), 2));
	
	setRefreshFlagFeeZero();
}
function calculatePremiumHurtMainOnlyZero(field, strCalculateShortRateFlag) {
	if (field.value == "" && parseFloat(field.value) != 0)
		return;
	calculatePremiumHurtMain(field, strCalculateShortRateFlag);
}
function calculatePremiumHurtSubOnlyZero(field, strCalculateShortRateFlag) {
	if (field.value == "" && parseFloat(field.value) != 0)
		return;
	calculatePremiumHurtSub(field, strCalculateShortRateFlag);
}

function setSumAmountPremiumToItemKindHurtMain(dbSumAmountHurtMain, dbSumPremiumHurtMain) {
	fm.SumAmountHurtMain.value = pointTwo(round(dbSumAmountHurtMain, 2));
	fm.CurrencySumAmountHurtMain.value = fm.Currency2Fee.value
	fm.CurrencyNameSumAmountHurtMain.value = fm.CurrencyName2Fee.value;
	fm.SumPremiumHurtMain.value = pointTwo(round(dbSumPremiumHurtMain, 2));
	fm.CurrencySumPremiumHurtMain.value = fm.Currency2Fee.value
	fm.CurrencyNameSumPremiumHurtMain.value = fm.CurrencyName2Fee.value;
}
function setSumAmountPremiumToItemKindHurtSub(dbSumAmountHurtSub, dbSumPremiumHurtSub) {
	fm.SumAmountHurtSub.value = pointTwo(round(dbSumAmountHurtSub, 2));
	fm.CurrencySumAmountHurtSub.value = fm.Currency2Fee.value
	fm.CurrencyNameSumAmountHurtSub.value = fm.CurrencyName2Fee.value;
	fm.SumPremiumHurtSub.value = pointTwo(round(dbSumPremiumHurtSub, 2));
	fm.CurrencySumPremiumHurtSub.value = fm.Currency2Fee.value
	fm.CurrencyNameSumPremiumHurtSub.value = fm.CurrencyName2Fee.value;
}
//人身伤害险
function insertItemKindHurt() {
	var intRowsCount = getRowsCount("ItemKindHurtMain");
	insertRow('ItemKindHurtMain', 'ItemKindHurtMain_Data');
	//fm.StartDateLoss[intRowsCount + 1].value = fm.StartDate.value;
	//fm.EndDateLoss[intRowsCount + 1].value = fm.EndDate.value;
	resetItemKindNo(); // 该函数在框架的js中
	//setItemKindAddressNoLoss();// 若被保险财产座落地址不为空将在主险中自动带出序号
	//calculatePremiumLoss(fm.ShortRateLoss[intRowsCount+1], 1);
}
function insertItemKindHurtSub() {
	var intRowsCount = getRowsCount("ItemKindHurtSub");
	insertRow('ItemKindHurtSub', 'ItemKindHurtSub_Data');
	//fm.StartDateLoss[intRowsCount + 1].value = fm.StartDate.value;
	//fm.EndDateLoss[intRowsCount + 1].value = fm.EndDate.value;
	resetItemKindNo(); // 该函数在框架的js中
	//setItemKindAddressNoLoss();// 若被保险财产座落地址不为空将在主险中自动带出序号
	//calculatePremiumLoss(fm.ShortRateLoss[intRowsCount+1], 1);
}



function checkItemKindHurtMain() {
	var intRowsCount = getRowsCount("ItemKindHurtMain");
	var i = 0;
	var j = 0;
	  var result =true;
	  var resulttemp =true;
	  var AllMessage="人身伤害险信息模块校验不通过，请关注红色录入域,重新填写正确的保单信息\n";
	  //校验之前如果没展开的话先打开，校验没有问题后关闭掉
	  elements =document.getElementsByName( "ItemKindHurtMainImg");
	  openPage(elements[0],ItemKindHurtMain);
	var arryList= ['KindCodeHurtMain','KindNameHurtMain','ItemDetailNameHurtMain','CurrencyHurtMain','UnitAmountHurtMain','QuantityHurtMain','AmountHurtMain','FamilyNameHurtMain','DiscountHurtMain','RateHurtMain','PremiumHurtMain'];
	for (i = 1; i <= intRowsCount; i++) {
		resulttemp = saveMessageValid(i,arryList,"");
		 if(resulttemp==false){
			 result =false;
			 }	
	}
    if(result==false){
        setcrollTo(elements[0]);
        ErrAllMessage(AllMessage);
    return  false;
    }
    
	for (i = 1; i <= intRowsCount; i++) {
		for (j = i + 1; j <= intRowsCount; j++) {
			if (fm.KindCodeHurtMain[i].value == fm.KindCodeHurtMain[j].value && fm.ItemCodeHurtMain[i].value==fm.ItemCodeHurtMain[j].value) {
				errorMessage(fm.KindCodeHurtMain[i].description+"与"+fm.ItemDetailNameHurtMain[i].description + "不能重复录入！");
				showPageOnly(document.ItemKindMainImg, ItemKindHurtMain);
				fm.ItemDetailNameHurtMain[i].focus();
				return false;
			}
		} 
	}
    setFlagPG('ItemKindHurtMain',2);
	closePage(elements[0],ItemKindHurtMain);
	return true;
}

function checkItemKindHurtSub() {
	var intRowsCount = getRowsCount("ItemKindHurtSub");
	var i = 0;
	var j = 0;
	  var result =true;
	  var resulttemp =true;
	  var AllMessage="人身伤害险信息模块校验不通过，请关注红色录入域,重新填写正确的保单信息\n";
	  //校验之前如果没展开的话先打开，校验没有问题后关闭掉
	  elements =document.getElementsByName( "ItemKindHurtSubImg");
	  openPage(elements[0],ItemKindHurtSub);
	var arryList= ['KindCodeHurtSub','KindNameHurtSub','ItemDetailNameHurtSub','CurrencyHurtSub','UnitAmountHurtSub','QuantityHurtSub','AmountHurtSub','FamilyNameHurtSub','DiscountHurtSub','RateHurtSub','PremiumHurtSub'];
	for (i = 1; i <= intRowsCount; i++) {
		resulttemp = saveMessageValid(i,arryList,"");
		 if(resulttemp==false){
			 result =false;
			 }	
	}
    if(result==false){
        setcrollTo(elements[0]);
        ErrAllMessage(AllMessage);
    return  false;
    }
    
	for (i = 1; i <= intRowsCount; i++) {
		for (j = i + 1; j <= intRowsCount; j++) {
			if (fm.KindCodeHurtSub[i].value == fm.KindCodeHurtSub[j].value && fm.ItemCodeHurtSub[i].value==fm.ItemCodeHurtSub[j].value) {
				errorMessage(fm.KindCodeHurtSub[i].description+"与"+fm.ItemDetailNameHurtSub[i].description + "不能重复录入！");
				showPageOnly(document.ItemKindSubImg, ItemKindHurtSub);
				fm.ItemDetailNameHurtSub[i].focus();
				return false;
			}
		} 
	}
    setFlagPG('ItemKindHurtSub',2);
	closePage(elements[0],ItemKindHurtSub);
	return true;
}



function deleteItemKindHurtMain(field,intPageDataKeyCount,intRowsCount)
{
  var index = getElementOrder(field)-1;
  var strFlag = fm.ItemKindHurtMain_Flag[index].value;
  
  deleteRowForPG('ItemKindHurtMain','ItemKindHurtMain_Data',field,intPageDataKeyCount,intRowsCount);
  resetItemKindNo();
  if(strFlag!="I"&&strFlag!="D")
  {
    fm.AmountHurtMain[index].value = "0.00";
    calculatePremiumHurtMain(fm.AmountHurtMain[index],1); //删除时需要重新计算短期系数
    //setRefreshFlagFeeZero();
  }
}
function deleteItemKindHurtSub(field,intPageDataKeyCount,intRowsCount)
{
  var index = getElementOrder(field)-1;
  var strFlag = fm.ItemKindHurtSub_Flag[index].value;
  
  deleteRowForPG('ItemKindHurtSub','ItemKindHurtSub_Data',field,intPageDataKeyCount,intRowsCount);
  resetItemKindNo();
  if(strFlag!="I"&&strFlag!="D")
  {
    fm.AmountHurtSub[index].value = "0.00";
    calculatePremiumHurtSub(fm.AmountHurtSub[index],1); //删除时需要重新计算短期系数
    //setRefreshFlagFeeZero();
  }
}


function setItemKindHurtMainEngageFlagPG()
{
  var index = 0;
  for(index=1;index<=getRowsCount("ItemKindHurtMain");index++)
  {
	fm.ItemKindHurtMainEngage_Flag[index].value = "";
	
    if(fm.ItemKindHurtMain_Flag[index].value!="U")
    {
      fm.ItemKindHurtMainEngage_Flag[index].value = fm.ItemKindHurtMain_Flag[index].value;
    }
    else
    {
     
	      if(fm.ItemKindHurtMain_Context[index].value!=fm.ItemKindHurtMain_Context[index].title)
	      {
	        fm.ItemKindHurtMainEngage_Flag[index].value = "U";
	      }
	      if(fm.PaymentRateHurtMain[index].value!=fm.PaymentRateHurtMain[index].title||
	         fm.DeductibleHurtMain[index].value!=fm.DeductibleHurtMain[index].title||
	         fm.ShortRateFlagHurtMain[index].value!=fm.ShortRateFlagHurtMain[index].title||
	         fm.ShortRateHurtMain[index].value!=fm.ShortRateHurtMain[index].title||
	         fm.KindCodeHurtMain[index].value!=fm.KindCodeHurtMain[index].title||
	         fm.KindNameHurtMain[index].value!=fm.KindNameHurtMain[index].title||
	         //fm.ItemNameHurtMain[index].value!=fm.ItemNameHurtMain[index].title||
	         //fm.ItemDetailNameHurtMain[index].value!=fm.ItemDetailNameHurtMain[index].title||
	         fm.CurrencyHurtMain[index].value!=fm.CurrencyHurtMain[index].title||
	         fm.AmountHurtMain[index].value!=fm.AmountHurtMain[index].title||
	         fm.RateHurtMain[index].value!=fm.RateHurtMain[index].title||
	         fm.PremiumHurtMain[index].value!=fm.PremiumHurtMain[index].title)
	      {
	        fm.ItemKindHurtMain_Flag[index].value = "U";
	      }
	      else
	      {
	    	  if(fm.ItemKindHurtMain_Flag[index].value != "U") {
	    		  fm.ItemKindHurtMain_Flag[index].value = "";
	    	  }
	      }
    }
  }
}

function setItemKindHurtSubEngageFlagPG()
{
  var index = 0;
  for(index=1;index<=getRowsCount("ItemKindHurtSub");index++)
  {
	fm.ItemKindHurtSubEngage_Flag[index].value = "";
	
    if(fm.ItemKindHurtSub_Flag[index].value!="U")
    {
      fm.ItemKindHurtSubEngage_Flag[index].value = fm.ItemKindHurtSub_Flag[index].value;
    }
    else
    {
     
	      if(fm.ItemKindHurtSub_Context[index].value!=fm.ItemKindHurtSub_Context[index].title)
	      {
	        fm.ItemKindHurtSubEngage_Flag[index].value = "U";
	      }
	      if(fm.PaymentRateHurtSub[index].value!=fm.PaymentRateHurtSub[index].title||
	         fm.DeductibleHurtSub[index].value!=fm.DeductibleHurtSub[index].title||
	         fm.ShortRateFlagHurtSub[index].value!=fm.ShortRateFlagHurtSub[index].title||
	         fm.ShortRateHurtSub[index].value!=fm.ShortRateHurtSub[index].title||
	         fm.KindCodeHurtSub[index].value!=fm.KindCodeHurtSub[index].title||
	         fm.KindNameHurtSub[index].value!=fm.KindNameHurtSub[index].title||
	         //fm.ItemNameHurtSub[index].value!=fm.ItemNameHurtSub[index].title||
	         //fm.ItemDetailNameHurtSub[index].value!=fm.ItemDetailNameHurtSub[index].title||
	         fm.CurrencyHurtSub[index].value!=fm.CurrencyHurtSub[index].title||
	         fm.AmountHurtSub[index].value!=fm.AmountHurtSub[index].title||
	         fm.RateHurtSub[index].value!=fm.RateHurtSub[index].title||
	         fm.PremiumHurtSub[index].value!=fm.PremiumHurtSub[index].title)
	      {
	        fm.ItemKindHurtSub_Flag[index].value = "U";
	      }
	      else
	      {
	    	  if(fm.ItemKindHurtSub_Flag[index].value != "U") {
	    		  fm.ItemKindHurtSub_Flag[index].value = "";
	    	  }
	      }
    }
  }
}


function getOldItemKindHurtMain()
{
  var arrayItemKindHurtMainRow = new Array();
  var arrayItemKindHurtMain = new Array();
  var i = 0;
  var j = 0;

  for(i=1;i<=getRowsCount("ItemKindHurtMain");i++)
  {
    arrayItemKindHurtMainRow = new Array();

	arrayItemKindHurtMainRow.KindCode = fm.KindCodeHurtMain[i].value;
	
	
	
	// xiaojian_leave：在页面上增加是否算入总保额的隐藏字段，在初始化文件中赋值：PrpDkind.CalculateFlag[1]
	 arrayItemKindHurtMainRow.CalculateFlag = fm.CalculateFlagHurtMain[i].value;
	//arrayItemKindHurtMainRow.CalculateFlag = "N";
	
	arrayItemKindHurtMainRow.ItemCode = fm.ItemCodeHurtMain[i].title;
	
	arrayItemKindHurtMainRow.Currency = fm.CurrencyHurtMain[i].title;
	
	arrayItemKindHurtMainRow.CurrencyName = fm.CurrencyNameHurtMain[i].title;
	
	arrayItemKindHurtMainRow.ExchangeRate = fm.ExchangeRateHurtMain[i].title;
	
	arrayItemKindHurtMainRow.Amount = parseFloat(fm.AmountHurtMain[i].value.replace(new RegExp(",","g"),""));
	
	arrayItemKindHurtMainRow.Rate = parseFloat(fm.RateHurtMain[i].title);
	
	arrayItemKindHurtMainRow.Discount = parseFloat(fm.DiscountHurtMain[i].title);
	
	arrayItemKindHurtMainRow.Premium = parseFloat(fm.PremiumHurtMain[i].title.replace(new RegExp(",","g"),""));
	
	if (isNaN(arrayItemKindHurtMainRow.ExchangeRate))
		arrayItemKindHurtMainRow.ExchangeRate = 0;
	if (isNaN(arrayItemKindHurtMainRow.Amount))
		arrayItemKindHurtMainRow.Amount = 0;
	if (isNaN(arrayItemKindHurtMainRow.Rate))
		arrayItemKindHurtMainRow.Rate = 0;
	if (isNaN(arrayItemKindHurtMainRow.Discount))
		arrayItemKindHurtMainRow.Discount = 0;
	if (isNaN(arrayItemKindHurtMainRow.Premium))
		arrayItemKindHurtMainRow.Premium = 0;
	
	arrayItemKindHurtMain[arrayItemKindHurtMain.length] = arrayItemKindHurtMainRow; // 一个标的信息
	
  }

  return arrayItemKindHurtMain;
}
function getOldItemKindHurtSub()
{
  var arrayItemKindHurtSubRow = new Array();
  var arrayItemKindHurtSub = new Array();
  var i = 0;
  var j = 0;

  for(i=1;i<=getRowsCount("ItemKindHurtSub");i++)
  {
    arrayItemKindHurtSubRow = new Array();

	arrayItemKindHurtSubRow.KindCode = fm.KindCodeHurtSub[i].value;
	
	
	
	// xiaojian_leave：在页面上增加是否算入总保额的隐藏字段，在初始化文件中赋值：PrpDkind.CalculateFlag[1]
	 arrayItemKindHurtSubRow.CalculateFlag = fm.CalculateFlagHurtSub[i].value;
	//arrayItemKindHurtMainRow.CalculateFlag = "N";
	
	arrayItemKindHurtSubRow.ItemCode = fm.ItemCodeHurtSub[i].title;
	
	arrayItemKindHurtSubRow.Currency = fm.CurrencyHurtSub[i].title;
	
	arrayItemKindHurtSubRow.CurrencyName = fm.CurrencyNameHurtSub[i].title;
	
	arrayItemKindHurtSubRow.ExchangeRate = fm.ExchangeRateHurtSub[i].title;
	
	arrayItemKindHurtSubRow.Amount = parseFloat(fm.AmountHurtSub[i].value.replace(new RegExp(",","g"),""));
	
	arrayItemKindHurtSubRow.Rate = parseFloat(fm.RateHurtSub[i].title);
	
	arrayItemKindHurtSubRow.Discount = parseFloat(fm.DiscountHurtSub[i].title);
	
	arrayItemKindHurtSubRow.Premium = parseFloat(fm.PremiumHurtSub[i].title.replace(new RegExp(",","g"),""));
	
	if (isNaN(arrayItemKindHurtSubRow.ExchangeRate))
		arrayItemKindHurtSubRow.ExchangeRate = 0;
	if (isNaN(arrayItemKindHurtSubRow.Amount))
		arrayItemKindHurtSubRow.Amount = 0;
	if (isNaN(arrayItemKindHurtSubRow.Rate))
		arrayItemKindHurtSubRow.Rate = 0;
	if (isNaN(arrayItemKindHurtSubRow.Discount))
		arrayItemKindHurtSubRow.Discount = 0;
	if (isNaN(arrayItemKindHurtSubRow.Premium))
		arrayItemKindHurtSubRow.Premium = 0;
	
	arrayItemKindHurtSub[arrayItemKindHurtSub.length] = arrayItemKindHurtSubRow; // 一个标的信息
	
  }

  return arrayItemKindHurtMain;
}
function collectByCurrencyAndCalculateFlag6603(arrayFee)
{
  var arrayReturn = new Array();
  var i = 0;
  var j = 0;
  var blnExist = false;
  for(i=0;i<arrayFee.length;i++)
  {
    blnExist = false;
    for(j=0;j<arrayReturn.length;j++)
    {//alert(arrayFee.length+" "+arrayFee[i].Amount);
      if(arrayFee[i].Currency==arrayReturn[j].Currency)
      {
        blnExist = true;
        break;
      }
    }
    if(blnExist)
    {
      arrayReturn[j].Premium = arrayReturn[j].Premium + arrayFee[i].Premium;
      if(arrayFee[i].CalculateFlag=="Y")
      {//if(fm.RiskCode.value == "6603")continue;/**changuish  因为6603财产险主险部分保费只算一个标的**/
        arrayReturn[j].Amount = arrayReturn[j].Amount + arrayFee[i].Amount;
        arrayReturn[j].CalculateFlag = "Y";
      }
    }
    else
    {
      if(arrayFee[i].CalculateFlag!="Y") arrayFee[i].Amount = 0;
      arrayReturn[arrayReturn.length] = arrayFee[i];
    }
    //if(fm.RiskCode.value == "6603")break;/**changuish**/
  }

  return arrayReturn;
}

function changecc(field){
var index = getElementOrder(field) - 1;

	var strkindcode = fm.KindCodeSub[index].value;
	/*if(strkindcode=="0193"||strkindcode=="0194"){
		document.getElementsByName("AmountSubSpan")[index].style.display="";
	}else{
		document.getElementsByName("AmountSubSpan")[index].style.display="none";
	}*/

}

function changeTurnoverLossSub(field){
	var index = getElementOrder(field) - 1;
	var strkindcode = fm.KindCodeLossSub[index].value;

	if(strkindcode=="0495"||strkindcode=="0496"||strkindcode=="0497"){
		
		//document.getElementsByName("UnitAmountLossSubSpan")[index].style.display="none";
		document.getElementsByName("UnitAmountLossSub")[index].readOnly=false;
		document.getElementsByName("UnitAmountLossSub")[index].value="0";
		//document.getElementsByName("LossAmountSubSpan")[index].style.display="none";
		document.getElementsByName("AmountLossSub")[index].readOnly=false;
		document.getElementsByName("AmountLossSub")[index].value="0";
		//document.getElementsByName("LossAmountSubSpan")[index].innerHTML="<input type=\'text\' name=\'TurnoverLossSub\' class=\'common\' style=\'width:100%\' maxlength=\'15\' value=\'0\' description=\'营业额\' onkeypress=\'return pressDecimal(event)\' onblur=\'checkDecimal(this,14,2,\'\',\'\')\' onchange=\'calculatePremiumLossSub(this,0)\'>";
		//document.getElementsByName("UnitAmountLossSubSpan")[index].innerHTML="<input type=\'text\' name=\'UnitAmountLossSub\' class=\'common\' style=\'width:65%\' maxlength=\'15\' value=\'0\' description=\'责任险附加条款每次事故每人赔偿限额\'>";
	}else{
		//document.getElementsByName("LossAmountSubSpan")[index].innerHTML="<select   name=\'TurnoverLossSub\' maxlength=\'5\'><option value=\'1000000\'>100万</option><option value=\'3000000\'>300万</option><option value=\'5000000\'>500万</option></select>";
		//document.getElementsByName("UnitAmountLossSubSpan")[index].innerHTML="<select name=\'UnitAmountLossSub\' style=\'width:35%\'><option value=\'20000\'>20000</option><option value=\'50000\'>50000</option><option value=\'100000\'>100000</option><option value=\'200000\'>200000</option><option value=\'无限额\'>无限额</option></select>";
	//	document.getElementsByName("LossAmountSuba")[index].style.display="";
	//	document.getElementsByName("LossAmountSubb")[index].style.display="none";	
		//document.getElementsByName("UnitAmountLossSubSpan")[index].style.display="";
		document.getElementsByName("UnitAmountLossSub")[index].readOnly=true;
		document.getElementsByName("UnitAmountLossSub")[index].value="0";
		//document.getElementsByName("LossAmountSubSpan")[index].style.display="";
		document.getElementsByName("AmountLossSub")[index].readOnly=true;
		document.getElementsByName("AmountLossSub")[index].value="0";
	}
}
//add by liuqinghua 附加险为 0495,0496,的时候控制可手动输入
function controlReadonly(field){
	var index = getElementOrder(field) - 1;
	var strkindcode = fm.KindCodeLossSub[index].value;
	if(strkindcode=="0495"||strkindcode=="0496"||strkindcode=="0497"){	
		//document.getElementsByName("UnitAmountLossSubSpan")[index].style.display="none";
		document.getElementsByName("UnitAmountLossSub")[index].readOnly=false;	
		//document.getElementsByName("LossAmountSubSpan")[index].style.display="none";
		document.getElementsByName("AmountLossSub")[index].readOnly=false;
		
	}
}
function changeUnitAmountLossSubSelect(field){
	var index = getElementOrder(field) - 1;
	if(fm.UnitAmountLossSubSelect[index].value!=1){
	document.getElementsByName("UnitAmountLossSub")[index].value=document.getElementsByName("UnitAmountLossSubSelect")[index].value
	}else{
		document.getElementsByName("UnitAmountLossSub")[index].value=document.getElementsByName("AmountLossSub")[index].value
	}
}
function changeUnitAmountLossSelect(field){
	var index = getElementOrder(field) - 1;
	if(fm.UnitAmountLossSelect[index].value!=1){
	document.getElementsByName("UnitAmountLoss")[index].value=document.getElementsByName("UnitAmountLossSelect")[index].value
	}else{
		document.getElementsByName("UnitAmountLoss")[index].value=document.getElementsByName("AmountLoss")[index].value
	}
	//if(fm.RiskCode.value == "6601" || fm.RiskCode.value == "6607"){
		fm.LIMITTYPE02Main[index].value=document.getElementsByName("UnitAmountLoss")[index].value;
	//}
}
function changeAmountLossSubSelect(field){
	var index = getElementOrder(field) - 1;
	document.getElementsByName("AmountLossSub")[index].value=document.getElementsByName("AmountLossSubselect")[index].value
	
}
function changeAmountLossSelect(field){
	var index = getElementOrder(field) - 1;
	document.getElementsByName("AmountLoss")[index].value=document.getElementsByName("AmountLossselect")[index].value
	//if(fm.RiskCode.value == "6601" || fm.RiskCode.value == "6607"){
		fm.LIMITTYPE04Main[index].value=document.getElementsByName("AmountLoss")[index].value;
	//}
	
}


function changeSele(field){
	var index = getElementOrder(field) - 1;
	
	var dbAmount = 0;
	var dbAmountTitle = 0;
	var dbAmountSubsele = 0;
	var intIndex = document.getElementsByName("button_ItemKindSub_Delete").length-1;
	if(intIndex>0){
		dbAmountSubsele = parseFloat(fm.AmountSubsele[index].value) /100 ;
		for (var i = 1; i <=fm.all("ItemCodeMain").length-1; i++) {
			if (fm.ItemCodeMain[i].value!='1') {
			     dbAmount += parseInt(fm.AmountMain[i].value);  // 保额	
			     dbAmountTitle  += parseInt(fm.AmountMain[i].title);//改变之前的总保额(除房屋)
			}
		}
		var strkindcode = fm.KindCodeSub[index].value;
		if(strkindcode=="0193"||strkindcode=="0194"){
			if(dbAmountSubsele == 0){//如果没有选中比例则计算原来的占比
				dbAmountSubsele = fm.AmountSub[index].title / dbAmountTitle;
			}
		    fm.AmountSub[index].value = pointTwo(round(dbAmount * dbAmountSubsele, 2)); 
		    calculatePremiumSub(fm.AmountSub[index], 0);
	  	}	
	}	
}

function changeSeleMain(field){
	//附加险个数
	for(var i = 1; i <=fm.all("KindCodeSub").length-1; i++)
	{   var strkindcode = fm.KindCodeSub[i].value;
		if(strkindcode=="0193"||strkindcode=="0194")
			changeSele(fm.AmountSubsele[i]);
		
	}
}

function mainChangePerumSub(field){
	//附加险个数
	for(var i = 1; i <=fm.all("KindCodeSub").length-1; i++)
	{   var strkindcode = fm.KindCodeSub[i].value;
		if(strkindcode=="0193"||strkindcode=="0194")
		calculatePremiumSub(fm.AmountSub[i], 0);
		
	}
}


function mainChangePerumSubdelete(field){
	//附加险个数
	var index = getElementOrder(field) - 1;
	for(var i = 1; i <=fm.all("KindCodeSub").length-1; i++)
	{   var strkindcode = fm.KindCodeSub[i].value;
		if(strkindcode=="0193"||strkindcode=="0194"){
			fm.AmountMain[index].value==0;
			changeSele(fm.AmountSubsele[i]);
			mainChangePerumSub(field);
		}
	}
}

function changeTurnover(){
	var intIndex = document.getElementsByName("button_ItemKindLoss_Delete").length-1;
	if(intIndex>0){
		for(var i = 1; i <=intIndex; i++){
			if(fm.Turnover.value!=""&&fm.Turnover.value!=null){
				fm.ValueLoss[i].value=fm.Turnover.value;
				calculatePremiumLoss(fm.ValueLoss[i], 0);
				setTurnover();
				
			   }else{
				   fm.ValueLoss.value=0.00;
				   calculatePremiumLoss(fm.ValueLoss[i], 0);
			   }
		}
	}
	var intIndex2= document.getElementsByName("button_ItemKindLossSub_Delete").length-1;
	if(intIndex2>0){
		for(var i = 1; i <=intIndex2; i++){
			if(fm.Turnover.value!=""&&fm.Turnover.value!=null){
				
				fm.ValueLossSub[i].value=fm.Turnover.value;
				calculatePremiumLossSub(fm.ValueLossSub[i], 0);
				setTurnover1();
				
			   }else{
				  
				   fm.ValueLossSub.value=0.00;
				   calculatePremiumLossSub(fm.ValueLossSub[i], 0);
			   }
		}
	}
}
//与保费相关的域发生变化，则短期费率方式默认按日比例计算
function setEndorseMain(){
	if(fm.RiskCode.value != "6606")return;
	/*for(index = 1; index < fm.PremiumMain.length; index++){/**财产主险*
		if(parseFloat(fm.AmountMain[index].value) == parseFloat(fm.AmountMain[index].title) && parseFloat(fm.RateMain[index].value) == parseFloat(fm.RateMain[index].title)){
			fm.ShortRateFlagMain[index].value = fm.ShortRateFlagMain[index].title;
			fm.all("ShortRateMain")[index].value  = fm.all("ShortRateMain")[index].title;
			fm.all("PremiumMain")[index].value = fm.all("PremiumMain")[index].title;
			setRefreshFlagFeeZero();
		}else{
			fm.ShortRateFlagMain[index].value = "2";
			calculatePremiumMain(fm.PremiumMain[index],1);
		}
	}*/
}
//与保费相关的域发生变化，则短期费率方式默认按日比例计算
function setEndorseSub(){
	if(fm.RiskCode.value != "6606")return;
	/*for(index = 1; index < fm.PremiumSub.length; index++){/**财产附加*
		if(parseFloat(fm.AmountSub[index].value) == parseFloat(fm.AmountSub[index].title) && parseFloat(fm.RateSub[index].value) == parseFloat(fm.RateSub[index].title)){
			fm.ShortRateFlagSub[index].value = fm.ShortRateFlagSub[index].title;
			fm.all("ShortRateSub")[index].value = fm.all("ShortRateSub")[index].title;
			fm.all("PremiumSub")[index].value = fm.all("PremiumSub")[index].title;
			setRefreshFlagFeeZero();
		}else{
			fm.ShortRateFlagSub[index].value = "2";
			calculatePremiumSub(fm.PremiumSub[index],1);
		}
	}*/
}
function setEndorseLoss(){
	if(fm.RiskCode.value != "6606")return;
	for(index = 1; index < fm.PremiumLoss.length; index++){/**责任主险**/
		if(parseFloat(fm.AmountLoss[index].value) == parseFloat(fm.AmountLoss[index].title) && parseFloat(fm.RateLoss[index].value) == parseFloat(fm.RateLoss[index].title)){
			fm.ShortRateFlagLoss[index].value = fm.ShortRateFlagLoss[index].title;
		    fm.all("ShortRateLoss")[index].value =  fm.all("ShortRateLoss")[index].title;
		    fm.all("PremiumLoss")[index].value = fm.all("PremiumLoss")[index].title;
		    setRefreshFlagFeeZero();
		}else{
			fm.ShortRateFlagLoss[index].value = "2";//日比例
			calculatePremiumLoss(fm.PremiumLoss[index],1);
		}
	}
}
function setEndorseLossSub(){
	if(fm.RiskCode.value != "6606")return;
	for(index = 1; index < fm.PremiumLossSub.length; index++){/**责任附加**/
		if(parseFloat(fm.AmountLossSub[index].value) == parseFloat(fm.AmountLossSub[index].title) && parseFloat(fm.RateLossSub[index].value) == parseFloat(fm.RateLossSub[index].title)){
			fm.ShortRateFlagLossSub[index].value = fm.ShortRateFlagLossSub[index].title;
		    fm.all("ShortRateLossSub")[index].value =  fm.all("ShortRateLossSub")[index].title;
		    fm.all("PremiumLossSub")[index].value = fm.all("PremiumLossSub")[index].title;
		    setRefreshFlagFeeZero();
		}else{
			fm.ShortRateFlagLossSub[index].value = "2";//日比例
			calculatePremiumLossSub(fm.PremiumLossSub[index],1);
		}
	}
}
function setItemKindMainLimitFlagPG()
{
  for(index=1;index<=getRowsCount("ItemKindLoss");index++)
  {
    if(fm.ItemKindLoss_Flag[index].value!="U")
    {
      fm.LIMITTYPE04Main_Flag[index].value = fm.ItemKindLoss_Flag[index].value;
      fm.LIMITTYPE01Main_Flag[index].value = fm.ItemKindLoss_Flag[index].value;
      fm.LIMITTYPE03Main_Flag[index].value = fm.ItemKindLoss_Flag[index].value;
      fm.LIMITTYPE07Main_Flag[index].value = fm.ItemKindLoss_Flag[index].value;
      fm.LIMITTYPE02Main_Flag[index].value = fm.ItemKindLoss_Flag[index].value;
      fm.LIMITTYPE24Main_Flag[index].value = fm.ItemKindLoss_Flag[index].value;
      fm.LIMITTYPE08Main_Flag[index].value = fm.ItemKindLoss_Flag[index].value;
      fm.LIMITTYPE12Main_Flag[index].value = fm.ItemKindLoss_Flag[index].value;
      fm.ItemKindMainLimit_Flag[index].value = fm.ItemKindLoss_Flag[index].value;
    }
    else
    {
      if(fm.LIMITTYPE04Main[index].value!=fm.LIMITTYPE04Main[index].title)
        fm.LIMITTYPE04Main_Flag[index].value = "U";
      if(fm.LIMITTYPE01Main[index].value!=fm.LIMITTYPE01Main[index].title)
        fm.LIMITTYPE01Main_Flag[index].value = "U";
      if(fm.LIMITTYPE03Main[index].value!=fm.LIMITTYPE03Main[index].title)
        fm.LIMITTYPE03Main_Flag[index].value = "U";
      if(fm.LIMITTYPE07Main[index].value!=fm.LIMITTYPE07Main[index].title)
        fm.LIMITTYPE07Main_Flag[index].value = "U";
      if(fm.LIMITTYPE02Main[index].value!=fm.LIMITTYPE02Main[index].title)
         fm.LIMITTYPE02Main_Flag[index].value = "U";
      if(fm.LIMITTYPE08Main[index].value!=fm.LIMITTYPE08Main[index].title)
          fm.LIMITTYPE08Main_Flag[index].value = "U";
      if(fm.LIMITTYPE24Main[index].value!=fm.LIMITTYPE24Main[index].title)
          fm.LIMITTYPE24Main_Flag[index].value = "U";
      if(fm.LIMITTYPE12Main[index].value!=fm.LIMITTYPE12Main[index].title)
          fm.LIMITTYPE12Main_Flag[index].value = "U";
      if(
         fm.LIMITTYPE04Main_Flag[index].value=="U"||
         fm.LIMITTYPE01Main_Flag[index].value=="U"||
         fm.LIMITTYPE03Main_Flag[index].value=="U"||
         fm.LIMITTYPE07Main_Flag[index].value=="U"||
         fm.LIMITTYPE02Main_Flag[index].value=="U"||
         fm.LIMITTYPE08Main_Flag[index].value=="U"||
         fm.LIMITTYPE12Main_Flag[index].value=="U"||
         fm.LIMITTYPE24Main_Flag[index].value=="U")//modify by renruide 20110729
      {
        fm.ItemKindMainLimit_Flag[index].value = "U";
      }
    }
  }
}
function setItemKindLossMainSubLimitFlagPG()
{
  for(index=1;index<=getRowsCount("ItemKindLossMainSub");index++)
  {
    if(fm.ItemKindLossMainSub_Flag[index].value!="U")
    {
      fm.LIMITTYPE90Sub_Flag[index].value = fm.ItemKindLoss_Flag[index].value;
      fm.LIMITTYPE91Sub_Flag[index].value = fm.ItemKindLoss_Flag[index].value;
      fm.LIMITTYPE92Sub_Flag[index].value = fm.ItemKindLoss_Flag[index].value;
      fm.LIMITTYPE93Sub_Flag[index].value = fm.ItemKindLoss_Flag[index].value;
      fm.LIMITTYPE94Sub_Flag[index].value = fm.ItemKindLoss_Flag[index].value;
      fm.LIMITTYPE95Sub_Flag[index].value = fm.ItemKindLoss_Flag[index].value;
      fm.LIMITTYPE96Sub_Flag[index].value = fm.ItemKindLoss_Flag[index].value;
      fm.LIMITTYPE97Sub_Flag[index].value = fm.ItemKindLoss_Flag[index].value;
      fm.ItemKindLossMainSub_Flag[index].value = fm.ItemKindLoss_Flag[index].value;
    }
    else
    {
      if(fm.LIMITTYPE90Sub[index].value!=fm.LIMITTYPE90Sub[index].title)
        fm.LIMITTYPE90Sub_Flag[index].value = "U";
      if(fm.LIMITTYPE91Sub[index].value!=fm.LIMITTYPE91Sub[index].title)
        fm.LIMITTYPE91Sub_Flag[index].value = "U";
      if(fm.LIMITTYPE92Sub[index].value!=fm.LIMITTYPE92Sub[index].title)
        fm.LIMITTYPE92Sub_Flag[index].value = "U";
      if(fm.LIMITTYPE93Sub[index].value!=fm.LIMITTYPE93Sub[index].title)
        fm.LIMITTYPE93Sub_Flag[index].value = "U";
      if(fm.LIMITTYPE94Sub[index].value!=fm.LIMITTYPE94Sub[index].title)
         fm.LIMITTYPE94Sub_Flag[index].value = "U";
      if(fm.LIMITTYPE95Sub[index].value!=fm.LIMITTYPE95Sub[index].title)
          fm.LIMITTYPE95Sub_Flag[index].value = "U";
      if(fm.LIMITTYPE96Sub[index].value!=fm.LIMITTYPE96Sub[index].title)
          fm.LIMITTYPE96Sub_Flag[index].value = "U";
      if(fm.LIMITTYPE97Sub[index].value!=fm.LIMITTYPE97Sub[index].title)
          fm.LIMITTYPE97Sub_Flag[index].value = "U";
      if(
         fm.LIMITTYPE90Sub_Flag[index].value=="U"||
         fm.LIMITTYPE91Sub_Flag[index].value=="U"||
         fm.LIMITTYPE92Sub_Flag[index].value=="U"||
         fm.LIMITTYPE93Sub_Flag[index].value=="U"||
         fm.LIMITTYPE94Sub_Flag[index].value=="U"||
         fm.LIMITTYPE95Sub_Flag[index].value=="U"||
         fm.LIMITTYPE96Sub_Flag[index].value=="U"||
         fm.LIMITTYPE97Sub_Flag[index].value=="U")//modify by renruide 20110729
      {
        fm.ItemKindLossMainSubLimit_Flag[index].value = "U";
      }
    }
  }
}
function checkLimitTypeVaule(){
	var intRowsCount = getRowsCount("ItemKindLoss");
	  var amountLoss=0.00;
	  var limitType01=0.00;
	  var limitType03=0.00;
	  var limitType07=0.00;
      for (i = 1; i <= intRowsCount; i++) {
		if (isEmpty(fm.LIMITTYPE01Main[i])) {
			errorMessage(fm.LIMITTYPE01Main[i].description + "不能为空！");
			showPageOnly(document.button_ItemKindLossLimit_Open, span_ItemKindLossLimit_SubPage[i]);
			fm.LIMITTYPE01Main[i].focus();
			return false;
		}
		
		
		if (isEmpty(fm.LIMITTYPE03Main[i])) {
			errorMessage(fm.LIMITTYPE03Main[i].description + "不能为空！");
			showPageOnly(document.button_ItemKindLossLimit_Open, span_ItemKindLossLimit_SubPage[i]);
			fm.LIMITTYPE03Main[i].focus();
			return false;
		}
		if (isEmpty(fm.LIMITTYPE07Main[i])) {
			errorMessage(fm.LIMITTYPE07Main[i].description + "不能为空！");
			showPageOnly(document.button_ItemKindLossLimit_Open, span_ItemKindLossLimit_SubPage[i]);
			fm.LIMITTYPE07Main[i].focus();
			return false;
		}
		amountLoss=parseFloat(fm.AmountLoss[i].value);
		limitType01=parseFloat(fm.LIMITTYPE01Main[i].value);
		limitType03=parseFloat(fm.LIMITTYPE03Main[i].value);
		limitType07=parseFloat(fm.LIMITTYPE07Main[i].value);
		if (isNaN(parseFloat(amountLoss))){
			amountLoss=0;
		}
		if (isNaN(parseFloat(limitType01))){
			limitType01=0;
		}
		if (isNaN(parseFloat(limitType03))){
			limitType03=0;
		}
		if (isNaN(parseFloat(limitType07))){
			limitType07=0;
		}
		if (limitType01==0) {
			errorMessage(fm.LIMITTYPE01Main[i].description + "不能为0！");
			showPageOnly(document.button_ItemKindLossLimit_Open, span_ItemKindLossLimit_SubPage[i]);
			fm.LIMITTYPE01Main[i].focus();
			return false;
		}
		if(limitType01>amountLoss){
			alert("每次事故赔偿限额不能大于累计赔偿限额，请重新输入！");	
			showPageOnly(document.button_ItemKindLossLimit_Open, span_ItemKindLossLimit_SubPage[i]);	
			fm.LIMITTYPE01Main[i].focus();
			return false;
		}
		if(limitType03>limitType01){
			alert("每次事故财产损失赔偿限额不能大于每次事故赔偿限额，请重新输入！");
			showPageOnly(document.button_ItemKindLossLimit_Open, span_ItemKindLossLimit_SubPage[i]);
			fm.LIMITTYPE03Main[i].focus();
			return false;
		}
		if(limitType07>limitType01){
			alert("每次事故人身伤亡赔偿限额不能大于每次事故赔偿限额，请重新输入！")
			showPageOnly(document.button_ItemKindLossLimit_Open, span_ItemKindLossLimit_SubPage[i]);
			fm.LIMITTYPE07Main[i].focus();
			return false;
		}
		
      }
      return true;
}

function setLimitTypeVaule(field){
	var index = getElementOrder(field) - 1;
	fm.UnitAmountLoss[index].value=document.getElementsByName("LIMITTYPE02Main")[index].value;
	fm.AmountLoss[index].value=document.getElementsByName("LIMITTYPE04Main")[index].value;
} 
function calculateAmountMain(index)
{
  var vUnitAmount=0;
  var vQuantity=0;
  var vAmount=0;
  if(!isNaN(fm.UnitAmountMain[index].value)&&!isNaN(fm.QuantityMain[index].value))
  {
    vUnitAmount=parseFloat(fm.UnitAmountMain[index].value);
    vQuantity=parseFloat(fm.QuantityMain[index].value);
    vAmount=parseFloat(vUnitAmount * vQuantity);
  }
  else if(!isNaN(fm.AmountMain[index].value))
  {
    vAmount=parseFloat(fm.AmountMain[index].value);
  }
  vAmount=pointTwo(vAmount);
  return vAmount;
}
}
